serializers
prefect.serializers
Serializer implementations for converting objects to bytes and bytes to objects.
All serializers are based on the Serializer
class and include a type
string that
allows them to be referenced without referencing the actual class. For example, you
can get often specify the JSONSerializer
with the string “json”. Some serializers
support additional settings for configuration of serialization. These are stored on
the instance so the same settings can be used to load saved objects.
All serializers must implement dumps
and loads
which convert objects to bytes and
bytes to an object respectively.
Functions
prefect_json_object_encoder
↗
JSONEncoder.default
for encoding objects into JSON with extended type support.
Raises a TypeError
to fallback on other encoders on failure.
prefect_json_object_decoder
↗
JSONDecoder.object_hook
for decoding objects from JSON when previously encoded
with prefect_json_object_encoder
Classes
Serializer
↗
A serializer that can encode objects of type ‘D’ into bytes.
Methods:
dumps
↗
Encode the object into a blob of bytes.
loads
↗
Decode the blob of bytes into an object.
PickleSerializer
↗
Serializes objects using the pickle protocol.
- Uses
cloudpickle
by default. Seepicklelib
for using alternative libraries. - Stores the version of the pickle library to check for compatibility during deserialization.
- Wraps pickles in base64 for safe transmission.
Methods:
check_picklelib
↗
dumps
↗
loads
↗
JSONSerializer
↗
Serializes data to JSON.
Input types must be compatible with the stdlib json library.
Wraps the json
library to serialize to UTF-8 bytes instead of string types.
Methods:
dumps_kwargs_cannot_contain_default
↗
loads_kwargs_cannot_contain_object_hook
↗
dumps
↗
loads
↗
CompressedSerializer
↗
Wraps another serializer, compressing its output.
Uses lzma
by default. See compressionlib
for using alternative libraries.
Methods:
validate_serializer
↗
check_compressionlib
↗
dumps
↗
loads
↗
CompressedPickleSerializer
↗
A compressed serializer preconfigured to use the pickle serializer.
CompressedJSONSerializer
↗
A compressed serializer preconfigured to use the json serializer.