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.8.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.8.0
File Size Uploaded Provenance Actions
serializable-1.8.0.tar.gz 31.2 kB Without provenance Details for serializable-1.8.0.tar.gz

Built distribution (wheel)

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

Total release size: 54.8 kB

Release files / serializable-1.8.0.tar.gz

Download URL serializable-1.8.0.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5641eadedeac1556f44a8b90754222e47964cb450992b6e04b89feef2d7856ce
BLAKE2b-256 checksum
How to use checksums
3687f3a724ba62cc14b8cac2d6aec080e9110e4bcdc3e5ccf295b39887098958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

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

Download URL serializable-1.8.0-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bde78bfd3a7d4c98ac6fd499a343c6ce131d287e52ba84902a1f6a0721f74fc7
BLAKE2b-256 checksum
How to use checksums
5ee5d4ed3a6c0871301876dc3b8f9f58a4e2e01ea735f73329993a9fa2338d8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for serializable 1.8.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