PseudoPickler

A simple plugin to work like pickle, in that it should hopefully support serializing arbitrary python objects, but which doesn’t attempt to put stuff down to a single bytearray, instead supporting objects with to_state and from_state methods by converting them to more primitive serializble types like arrays, strings, numbers, etc. Falls back to naive pickling when necessary.

 

__init__(self, allow_pickle=False, protocol=1, b64encode=False): 

LLM Docstring

Configure pseudo-pickling fallback, protocol marker, and optional base64 encoding for embedded pickle bytes.

  • allow_pickle: object

    whether unsupported values may fall back to pickle

  • protocol: object

    pseudo-pickle protocol marker

  • b64encode: object

    whether pickle bytes are base64 encoded

  • :returns: None

    No explicit value; the method mutates state or performs I/O.

 

to_state(self, obj, cache=None): 

Tries to extract state from obj, first through its to_state interface, but that failing by recursively walking the object tree

  • obj: Any
  • :returns: _

 

serialize(self, obj, cache=None): 

Serializes an object first by checking for a to_state method, and that missing, by converting to primitive-ish types in a recursive strategy if the object passes is_simple, otherwise falling back to pickle

  • obj: Any

    object to be serialized

  • :returns: dict

    spec for the pseudo-pickled data

 

deserialize(self, spec): 

Deserializes from an object spec, dispatching to regular pickle where necessary

  • object: Any
  • :returns: _

Feedback

Examples

Templates

Documentation