Skip to main content

Tests Documentation PyPI PyPI downloads

serializable

serializable saves Python objects as JSON or pickles and reconstructs the same classes, including nested objects. Subclass DataclassSerializable for a dataclass, or Serializable for a class whose constructor arguments describe its state. It is the serialization layer of the OpenVax libraries: varcode and vaxrank results, pyensembl genomes and sercol collections all save and reload through it.

Install

python -m pip install serializable

Python 3.11 or later is required.

Quick start

from dataclasses import dataclass
from serializable import DataclassSerializable

@dataclass
class Point(DataclassSerializable):
    x: float
    y: float

point = Point(1.0, 2.0)
restored = Point.from_json(point.to_json())
print(point.to_dict())
print(restored)
print(restored == point)
{'x': 1.0, 'y': 2.0}
Point(x=1.0, y=2.0)
True

to_dict() gives the constructor fields; to_json() also records the class and its module so from_json() can rebuild it. The dataclass keeps its own generated constructor, equality, representation and hashing. The recorded module and class must be importable when loading, so load data only from sources you trust. A class or function defined inside another function can't be looked up again, so serializing it raises ValueError.

Documentation

The documentation covers, in reading order:

  1. Getting started: the example above, choosing a base class, and the format's limits.
  2. Save classes and files: constructor-based classes, JSON files, pickles and nested containers.
  3. Change field names: read data written before a constructor argument was renamed.
  4. API reference.

Development

./develop.sh   # strict editable install with dev dependencies into .venv
./format.sh   # ruff format
./lint.sh     # ruff check, ruff format --check and mypy
./test.sh     # pytest with coverage
python -m pip install -r requirements-docs.txt
./docs.sh     # mkdocs build --strict, then a rendered-link check
python scripts/check_docs_examples.py   # run docs examples, compare output

To install a checkout into another environment, use a strict editable install so type checkers in projects which depend on serializable can find it:

python -m pip install -C editable_mode=strict -e .

Rerun that after adding or renaming a file in serializable/, or after deleting the checkout's build/ directory, which is where the installed link tree lives. Edits to existing files are picked up immediately.

Every PR bumps serializable/version.py. Maintainers release with ./deploy.sh from a clean master.

License

Apache 2.0; see LICENSE.

Metadata

Release files for serializable 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for serializable 1.7.0
File Size Uploaded Provenance Actions
serializable-1.7.0.tar.gz 32.1 kB Without provenance Details for serializable-1.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for serializable 1.7.0
File Interpreter ABI Platform Actions
serializable-1.7.0-py3-none-any.whl Python 3 none any Details for serializable-1.7.0-py3-none-any.whl

Total release size: 56.1 kB

Release files / serializable-1.7.0.tar.gz

Download URL serializable-1.7.0.tar.gz
Size 32.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9f5ebdf619272a13c15ec058c49ce078e24ec1d249725c24b4765da1214b2e9f
BLAKE2b-256 checksum
How to use checksums
95b89c0353e7de5a2fd2eab3598e75050221458bbe8df9e49d3096f9dc4a0c00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release files / serializable-1.7.0-py3-none-any.whl

Download URL serializable-1.7.0-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa2813bc889c6cafaf86eb4399ab2981aa12cafa61ed5fbc6fc312f93acfd856
BLAKE2b-256 checksum
How to use checksums
12fd47a2bd73092c9015fe4bc1680f1debe4ae67a1119725efdb7faaa5a7d9c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Security for serializable 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

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