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.6.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.6.0
File Size Uploaded Provenance Actions
serializable-1.6.0.tar.gz 31.6 kB Without provenance Details for serializable-1.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 55.4 kB

Release files / serializable-1.6.0.tar.gz

Download URL serializable-1.6.0.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1746b8f6629cc59ac010e450d23c83a928c7bd40e0c690b27273c7059b624ea0
BLAKE2b-256 checksum
How to use checksums
702980db723e1b001bc02bb6e42cad0233cae047a345f49d920004ba1c4555e5
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.6.0-py3-none-any.whl

Download URL serializable-1.6.0-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb36d005f59fc908e9f42d36d4b4e808e037d5f018518b904a802fc91d2f287b
BLAKE2b-256 checksum
How to use checksums
c6c9a008f110d33ba127b54a93e8b9b9e4b3ed738215c07e4aa4ca48b9071ffe
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.6.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