Skip to main content

Base class with serialization helpers for user-defined Python objects

Project description

Tests PyPI PyPI downloads

serializable

Base class with serialization methods for user-defined Python objects

Usage

Classes which inherit from Serializable are enabled with default implementations of to_json, from_json, __reduce__ (for pickling), and other serialization helpers.

A derived class must either:

  • have a member data matching the name of each argument to __init__
  • provide a user-defined to_dict() method which returns a dictionary whose keys match the arguments to __init__

If you change the keyword arguments to a class which derives from Serializable but would like to be able to deserialize older JSON representations then you can define a class-level dictionary called _KEYWORD_ALIASES which maps old keywords to new names (or None if a keyword was removed).

Limitations

  • Serializable objects must inherit from Serializable, be tuples or namedtuples, be serializble primitive types such as dict, list, int, float, or str.

  • The serialized representation of objects relies on reserved keywords (such as "__name__", and "__class__"), so dictionaries are expected to not contain any keys which begin with two underscores.

Project details


Download files

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

Source Distribution

serializable-0.4.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

serializable-0.4.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file serializable-0.4.1.tar.gz.

File metadata

  • Download URL: serializable-0.4.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.10

File hashes

Hashes for serializable-0.4.1.tar.gz
Algorithm Hash digest
SHA256 882098d79253d38591a3d4d7d5d78052fce3ba4d29d64c1704d73f1a19d066d8
MD5 6c47f0eb181d62d59949dfa1661813ad
BLAKE2b-256 172998d529dbd22b079ad29a80531cef271894ed2aaf4f3310b8c3b102c95e4e

See more details on using hashes here.

File details

Details for the file serializable-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: serializable-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.10

File hashes

Hashes for serializable-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1f09fade42cc49f9cdf138cd8d2d3515beb1605507ae26983ea812bae77b3e2
MD5 3883f4ad315af1b15b68353869652a5f
BLAKE2b-256 bda6736a99c39baa85cf51922526525300fb732f2d31138c28ae1634370bf8bf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page