Skip to main content

Base class with serialization helpers for user-defined Python objects

Project description

Base class with serialization methods for user-defined Python objects

Usage

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

Your derived class must:

  • provide a user-defined to_dict() method which returns a dictionary whose keys are strings and whose values are all primitive serializable types (list, dict, int, str, &c).

  • The keys of the dictionary returned by to_dict() must match the arguments to the __init__ of your class.

Limitations

  • Nested objects must also inherit from Serializable and must be manually converted to serializable types in to_dict() and then reconstructed by overriding the class method _reconstruct_nested_objects.

  • Functions defined at the top level of a module can be converted to primtive types with function_to_serializable_representation, but this helper will fail for methods.

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.0.2.tar.gz (5.0 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for serializable-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1f5b6aab7fd133093fac53b9dca27fad50e175c5d50f72f2227dea3020b32205
MD5 97c72fdd0d1bee437d5d7fab1920fcab
BLAKE2b-256 1ea0b82cb43a18bc4567a44c1b3067311f9840e1bad53393bdb672930086fbe5

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