Base class with serialization helpers for user-defined Python objects
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for serializable-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce756a8e9a2e1ccee4c1ddbb4f33a677c4132c68220abd79ed7db4b56c9b787c |
|
MD5 | eaa7f90a1d2afb185687bfc9ab31e11c |
|
BLAKE2b-256 | ee1dfc08c06ffde841414a02799d70ccee2c0f3cfed48ef1df3495b7889f7017 |