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
File details
Details for the file serializable-0.3.0.tar.gz
.
File metadata
- Download URL: serializable-0.3.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 301d11dcb36ce799d4bbc77bf54bae846050af166a89f256ab9ce92ca1f42b03 |
|
MD5 | 13e05ec9f3e9473418f6b4b2ee130509 |
|
BLAKE2b-256 | 914fb5d0a71b3f85efda671bb2fc4589d3911bd035025353508a5e8d04a248d6 |
File details
Details for the file serializable-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: serializable-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa172474e57437fffab01a01444661f7577bf88aa802313e705afcf0bdbfce53 |
|
MD5 | e3a7acc3738a869e32c772a93410d965 |
|
BLAKE2b-256 | de8fab51fbeacbd3fcc527032b4e99139370dc5ce09c734a83dfb9be51d78479 |