pickle
pickle.dumps(obj) -> bytes
Return the pickled representation of an object as a bytes object.
pickle.loads(b: bytes)
Return the unpickled object from a bytes object.
What can be pickled and unpickled?
The following types can be pickled:
- None, True, and False;
- integers, floating-point numbers;
- strings, bytes;
- tuples, lists, sets, and dictionaries containing only picklable objects;
- functions (user-defined) accessible from the top level of a module (using def, not lambda);
- classes accessible from the top level of a module;
- instances of such classes
Cyclic and shared references are preserved: list, dict and instances of
python classes are memoized before their contents are written, so an object
graph containing reference cycles round-trips correctly and object identity
is retained. A cycle that passes only through a tuple or through a
__reduce__ result is not supported.
The following magic methods are available:
-
__getnewargs__ -
__getstate__ -
__setstate__ -
__reduce__