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.

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

python -m pip install -e ".[dev]"   # or ./develop.sh, which uses .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

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.3.4

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.3.4
File Size Uploaded Provenance Actions
serializable-1.3.4.tar.gz 26.4 kB Without provenance Details for serializable-1.3.4.tar.gz

Built distribution (wheel)

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

Total release size: 48.4 kB

Release files / serializable-1.3.4.tar.gz

Download URL serializable-1.3.4.tar.gz
Size 26.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e6be85e052da92cd06d2c36c6571a7c73ce44fa89cd32d36114f16935373bf09
BLAKE2b-256 checksum
How to use checksums
5c2e58f91d24a949089736a3252fd074ca79f11baf709e880026e90ad2cf2b30
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.3.4-py3-none-any.whl

Download URL serializable-1.3.4-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea4e910a5c6ed5c0b9cae2da56119714a051f7008f3995f0eec0c556684bdcaa
BLAKE2b-256 checksum
How to use checksums
35e2b7e028708317efb24f17af208607e370666f6d1b55a7bcc18aa58a1b3055
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.3.4

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.

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