pickle.Unpickler.find_class()

find_class(module, name) Import module if necessary and return the object called name from it, where the module and name arguments are str objects. Note, unlike its name suggests, find_class() is also used for finding functions. Subclasses may override this to gain control over what type of objects and how they can be loaded, potentially reducing security risks. Refer to Restricting Globals for details.

pickle.Unpickler

class pickle.Unpickler(file, *, fix_imports=True, encoding="ASCII", errors="strict") This takes a binary file for reading a pickle data stream. The protocol version of the pickle is detected automatically, so no protocol argument is needed. The argument file must have two methods, a read() method that takes an integer argument, and a readline() method that requires no arguments. Both methods should return bytes. Thus file can be an on-disk file object opened for binary reading, an io.BytesIO

pickle.PicklingError

exception pickle.PicklingError Error raised when an unpicklable object is encountered by Pickler. It inherits PickleError. Refer to What can be pickled and unpickled? to learn what kinds of objects can be pickled.

pickle.Pickler.persistent_id()

persistent_id(obj) Do nothing by default. This exists so a subclass can override it. If persistent_id() returns None, obj is pickled as usual. Any other value causes Pickler to emit the returned value as a persistent ID for obj. The meaning of this persistent ID should be defined by Unpickler.persistent_load(). Note that the value returned by persistent_id() cannot itself have a persistent ID. See Persistence of External Objects for details and examples of uses.

pickle.Pickler.fast

fast Deprecated. Enable fast mode if set to a true value. The fast mode disables the usage of memo, therefore speeding the pickling process by not generating superfluous PUT opcodes. It should not be used with self-referential objects, doing otherwise will cause Pickler to recurse infinitely. Use pickletools.optimize() if you need more compact pickles.

pickle.Pickler.dump()

dump(obj) Write a pickled representation of obj to the open file object given in the constructor.

pickle.Pickler.dispatch_table

dispatch_table A pickler object’s dispatch table is a registry of reduction functions of the kind which can be declared using copyreg.pickle(). It is a mapping whose keys are classes and whose values are reduction functions. A reduction function takes a single argument of the associated class and should conform to the same interface as a __reduce__() method. By default, a pickler object will not have a dispatch_table attribute, and it will instead use the global dispatch table managed by the

pickle.Pickler

class pickle.Pickler(file, protocol=None, *, fix_imports=True) This takes a binary file for writing a pickle data stream. The optional protocol argument, an integer, tells the pickler to use the given protocol; supported protocols are 0 to HIGHEST_PROTOCOL. If not specified, the default is DEFAULT_PROTOCOL. If a negative number is specified, HIGHEST_PROTOCOL is selected. The file argument must have a write() method that accepts a single bytes argument. It can thus be an on-disk file opened f

pickle.PickleError

exception pickle.PickleError Common base class for the other pickling exceptions. It inherits Exception.

pickle.loads()

pickle.loads(bytes_object, *, fix_imports=True, encoding="ASCII", errors="strict") Read a pickled object hierarchy from a bytes object and return the reconstituted object hierarchy specified therein. The protocol version of the pickle is detected automatically, so no protocol argument is needed. Bytes past the pickled object’s representation are ignored. Optional keyword arguments are fix_imports, encoding and errors, which are used to control compatibility support for pickle stream generate