@@ -85,45 +85,48 @@ Data stream format
85
85
------------------
86
86
87
87
.. index ::
88
- single: XDR
89
88
single: External Data Representation
90
89
91
90
The data format used by :mod: `pickle ` is Python-specific. This has the
92
91
advantage that there are no restrictions imposed by external standards such as
93
- XDR (which can't represent pointer sharing); however it means that non-Python
94
- programs may not be able to reconstruct pickled Python objects.
92
+ JSON or XDR (which can't represent pointer sharing); however it means that
93
+ non-Python programs may not be able to reconstruct pickled Python objects.
94
+
95
+ By default, the :mod: `pickle ` data format uses a relatively compact binary
96
+ representation. If you need optimal size characteristics, you can efficiently
97
+ :doc: `compress <archiving >` pickled data.
95
98
96
- By default, the :mod: `pickle ` data format uses a compact binary representation.
97
99
The module :mod: `pickletools ` contains tools for analyzing data streams
98
- generated by :mod: `pickle `.
100
+ generated by :mod: `pickle `. :mod: `pickletools ` source code has extensive
101
+ comments about opcodes used by pickle protocols.
99
102
100
103
There are currently 4 different protocols which can be used for pickling.
101
104
102
- * Protocol version 0 is the original human-readable protocol and is
105
+ * Protocol version 0 is the original " human-readable" protocol and is
103
106
backwards compatible with earlier versions of Python.
104
107
105
- * Protocol version 1 is the old binary format which is also compatible with
108
+ * Protocol version 1 is an old binary format which is also compatible with
106
109
earlier versions of Python.
107
110
108
111
* Protocol version 2 was introduced in Python 2.3. It provides much more
109
- efficient pickling of :term: `new-style class `\e s.
112
+ efficient pickling of :term: `new-style class `\e s. Refer to :pep: `307 ` for
113
+ information about improvements brought by protocol 2.
110
114
111
- * Protocol version 3 was added in Python 3.0. It has explicit support for
112
- bytes and cannot be unpickled by Python 2.x pickle modules. This is
113
- the current recommended protocol, use it whenever it is possible.
114
-
115
- Refer to :pep: `307 ` for information about improvements brought by
116
- protocol 2. See :mod: `pickletools `'s source code for extensive
117
- comments about opcodes used by pickle protocols.
115
+ * Protocol version 3 was added in Python 3. It has explicit support for
116
+ :class: `bytes ` objects and cannot be unpickled by Python 2.x. This is
117
+ the default as well as the current recommended protocol; use it whenever
118
+ possible.
118
119
119
120
120
121
Module Interface
121
122
----------------
122
123
123
- To serialize an object hierarchy, you first create a pickler, then you call the
124
- pickler's :meth: `dump ` method. To de-serialize a data stream, you first create
125
- an unpickler, then you call the unpickler's :meth: `load ` method. The
126
- :mod: `pickle ` module provides the following constant:
124
+ To serialize an object hierarchy, you simply call the :func: `dumps ` function.
125
+ Similarly, to de-serialize a data stream, you call the :func: `loads ` function.
126
+ However, if you want more control over serialization and de-serialization,
127
+ you can create a :class: `Pickler ` or an :class: `Unpickler ` object, respectively.
128
+
129
+ The :mod: `pickle ` module provides the following constants:
127
130
128
131
129
132
.. data :: HIGHEST_PROTOCOL
@@ -134,8 +137,7 @@ an unpickler, then you call the unpickler's :meth:`load` method. The
134
137
.. data :: DEFAULT_PROTOCOL
135
138
136
139
The default protocol used for pickling. May be less than HIGHEST_PROTOCOL.
137
- Currently the default protocol is 3; a backward-incompatible protocol
138
- designed for Python 3.0.
140
+ Currently the default protocol is 3, a new protocol designed for Python 3.0.
139
141
140
142
141
143
The :mod: `pickle ` module provides the following functions to make the pickling
0 commit comments