Skip to main content

Serialite

Serialite is a library serializing and deserializing arbitrarily complex objects in Python. You apply the @serializable decorator to a dataclass to automatically create to_data and from_data methods using the type annotations. Or for more control, inherit from the SerializableMixin and implement the class attribute __fields_serializer__. For even more control, inherit from the abstract base class Serializer and implement the to_data and from_data methods directly.

Basics

The abstract base class is Serializer:

class Serializer(Generic[Output]):
    def from_data(self, data: Json) -> DeserializationSuccess[Output]: ...
    def to_data(self, value: Output) -> Json: ...

The class is generic in the type of the object that it serializes. The two abstract methods from_data and to_data are the key to the whole design, which revolves around getting objects to and from JSON-serializable data, which are objects constructed entirely of bools, ints, floats, lists, and dicts. Such structures can be consumed by json.dumps to produce a string and produced by json.loads after consuming a string. By basing the serialization around JSON serializable data, complex structures can be built up or torn down piece by piece while alternatively building up complex error messages during deserialization which pinpoint the location in the structure where the bad data exist.

For new classes, it is recommended that the Serializer be implemented on the class itself. There is an abstract base class Serializable that classes can inherit from to indicate this. There is a mixin SerializableMixin that provides an implementation of from_data and to_data for any class that implements the __fields_serializer class attribute.

For dataclasses, it is even easier. There is a decorator serializable that inserts SerializableMixin into the list of base classes after the dataclass decorator has run and also generates __fields_serializer__ from the data class attributes.

Finding the correct serializer for each type can be a pain, so serializer(cls: type) -> Serializer is provided as a convenience function. This is a single dispatch function, which looks up the serializer registered for a particular type. For example, serializer(list[float]) will return ListSerializer(FloatSerializer).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serialite-0.6.4.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serialite-0.6.4-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

Details for the file serialite-0.6.4.tar.gz.

File metadata

  • Download URL: serialite-0.6.4.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for serialite-0.6.4.tar.gz
Algorithm Hash digest
SHA256 06059e4aa1313cf98acbe057ce3658ccdee379541804c333413a5fab2ed15578
MD5 5b525235d688ca965135c8e9f3abd649
BLAKE2b-256 b4b47604a713c56c0e54d77237960b0ba3a8e0dd5bb3356ad97c175a72d4c58f

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialite-0.6.4.tar.gz:

Publisher: release.yml on drhagen/serialite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serialite-0.6.4-py3-none-any.whl.

File metadata

  • Download URL: serialite-0.6.4-py3-none-any.whl
  • Upload date:
  • Size: 42.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for serialite-0.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 871bb35c823e31360da277fc516269c6214e664075e53fbdfa0646515ba711f9
MD5 7087edc0e9f1794aecec6cf6b4b53481
BLAKE2b-256 1fae6494baaf59088c790ebd6a06993714c28c6a5839e36731fe3717d57a0a09

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialite-0.6.4-py3-none-any.whl:

Publisher: release.yml on drhagen/serialite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.6.4 This release

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page