picklers

Has two main parts:

  1. The picklersIO classes (all BasePicklerIO subclasses)

  2. The picklerIO registry.

The picklerIO classes must provide a minimum signature defined in the the common base class: BasePicklerIO, and are in charge of writing or reading serialized python objects into and from file-like objects.

registry.get_pickler(name)

Get the PicklerIO class registered with a given pickler name.

registry.register_pickler(name, pickler)

Register a pickler handler.

registry.get_known_picklers()

Get a list of known pickle serialization methods.

registry.list_registered_picklers()

Get the list of registered PicklerIO classes.

base.BasePicklerIO()

PicklerIO abstract base class.

pickle.BuiltinPicklerIO()

A PicklerIO class that wraps standard pickle.dump() and pickle.load().

optimized_pickle.OptimizedPicklerIO()

A PicklerIO class that combines pickletools.optimize() and standard pickle.dump().

marshal.MarshalPicklerIO()

A PicklerIO class that wraps standard marshal.dump() and marshal.load().

dill.DillPicklerIO()

A PicklerIO class that wraps dill.dump and dill.load.

cloudpickle.CloudPicklerIO()

A PicklerIO class that wraps cloudpickle.dump and cloudpickle.load.

Registry

compress_pickle.picklers.registry.get_known_picklers() List[str][source]

Get a list of known pickle serialization methods.

Returns

List of known pickler serialization methods.

Return type

List[str]

compress_pickle.picklers.registry.get_pickler(name: str) Type[compress_pickle.picklers.base.BasePicklerIO][source]

Get the PicklerIO class registered with a given pickler name.

Parameters

name (str) – The pickler name.

Raises

ValueError – If the supplied name has not been registered.

Returns

The PicklerIO class associated to the pickler name.

Return type

BasePicklerIO

compress_pickle.picklers.registry.list_registered_picklers() List[Type[compress_pickle.picklers.base.BasePicklerIO]][source]

Get the list of registered PicklerIO classes.

Returns

The list of registered pickler classes.

Return type

List[BasePicklerIO]

compress_pickle.picklers.registry.register_pickler(name: str, pickler: Type[compress_pickle.picklers.base.BasePicklerIO])[source]

Register a pickler handler.

Parameters
  • name (str) – The pickler name that will be registered.

  • pickler (Type[BasePicklerIO]) – The PicklerIO class. This should be a BasePicklerIO subclass.

Raises

PicklerIO

class compress_pickle.picklers.base.BasePicklerIO[source]

PicklerIO abstract base class.

This class is in charge of writing and reading serialized python objects from a file-like binary stream.

abstract dump(obj: Any, stream: IO[bytes], **kwargs)[source]

Write a serialized binary representation of an object to a stream.

Parameters
  • obj (Any) – The python object that must be serialized and written.

  • stream (IO[bytes]) – The binary stream (file-like object) where the serialized object must be written to.

  • kwargs – Any extra keyword arguments that are needed in the concrete implementation of dump.

abstract load(stream: IO[bytes], **kwargs)[source]

Load a serialized binary representation of an object from a stream.

Parameters
  • stream (IO[bytes]) – The binary stream (file-like object) from where the serialized object must be loaded.

  • kwargs – Any extra keyword arguments that are needed in the concrete implementation of load.

Returns

obj – The python object that was loaded.

Return type

Any

class compress_pickle.picklers.pickle.BuiltinPicklerIO[source]

A PicklerIO class that wraps standard pickle.dump() and pickle.load().

dump(obj: Any, stream: IO[bytes], **kwargs)[source]

Write a serialized binary representation of an object to a stream.

Parameters
  • obj (Any) – The python object that must be serialized and written.

  • stream (IO[bytes]) – The binary stream (file-like object) where the serialized object must be written to.

  • kwargs – Any extra keyword arguments to pass to pickle.dump().

load(stream: IO[bytes], **kwargs)[source]

Load a serialized binary representation of an object from a stream.

Parameters
  • stream (IO[bytes]) – The binary stream (file-like object) from where the serialized object must be loaded.

  • kwargs – Any extra keyword arguments to pass to pickle.load().

Returns

obj – The python object that was loaded.

Return type

Any

class compress_pickle.picklers.optimized_pickle.OptimizedPicklerIO[source]

A PicklerIO class that combines pickletools.optimize() and standard pickle.dump().

dump(obj: Any, stream: IO[bytes], **kwargs)[source]

Write a serialized binary representation of an object to a stream.

Parameters
  • obj (Any) – The python object that must be serialized and written.

  • stream (IO[bytes]) – The binary stream (file-like object) where the serialized object must be written to.

  • kwargs – Any extra keyword arguments to pass to pickle.dump().

class compress_pickle.picklers.marshal.MarshalPicklerIO[source]

A PicklerIO class that wraps standard marshal.dump() and marshal.load().

dump(obj: Any, stream: IO[bytes], **kwargs)[source]

Write a serialized binary representation of an object to a stream.

Parameters
  • obj (Any) – The python object that must be serialized and written.

  • stream (IO[bytes]) – The binary stream (file-like object) where the serialized object must be written to.

  • kwargs – Any extra keyword arguments to pass to marshal.dump().

load(stream: IO[bytes], **kwargs)[source]

Load a serialized binary representation of an object from a stream.

Parameters
  • stream (IO[bytes]) – The binary stream (file-like object) from where the serialized object must be loaded.

  • kwargs – Any extra keyword arguments to pass to marshal.load().

Returns

obj – The python object that was loaded.

Return type

Any

class compress_pickle.picklers.dill.DillPicklerIO[source]

A PicklerIO class that wraps dill.dump and dill.load.

dump(obj: Any, stream: IO[bytes], **kwargs)[source]

Write a serialized binary representation of an object to a stream.

Parameters
  • obj (Any) – The python object that must be serialized and written.

  • stream (IO[bytes]) – The binary stream (file-like object) where the serialized object must be written to.

  • kwargs – Any extra keyword arguments to pass to dill.dump.

load(stream: IO[bytes], **kwargs)[source]

Load a serialized binary representation of an object from a stream.

Parameters
  • stream (IO[bytes]) – The binary stream (file-like object) from where the serialized object must be loaded.

  • kwargs – Any extra keyword arguments to pass to dill.load.

Returns

obj – The python object that was loaded.

Return type

Any

class compress_pickle.picklers.cloudpickle.CloudPicklerIO[source]

A PicklerIO class that wraps cloudpickle.dump and cloudpickle.load.

dump(obj: Any, stream: IO[bytes], **kwargs)[source]

Write a serialized binary representation of an object to a stream.

Parameters
  • obj (Any) – The python object that must be serialized and written.

  • stream (IO[bytes]) – The binary stream (file-like object) where the serialized object must be written to.

  • kwargs – Any extra keyword arguments to pass to cloudpickle.dump.

load(stream: IO[bytes], **kwargs)[source]

Load a serialized binary representation of an object from a stream.

Parameters
  • stream (IO[bytes]) – The binary stream (file-like object) from where the serialized object must be loaded.

  • kwargs – Any extra keyword arguments to pass to cloudpickle.load.

Returns

obj – The python object that was loaded.

Return type

Any