Skip to main content

Easy-Serialize

Turn custom python objects into strings and vice-versa.

Strengths

  • no extra code to write in most cases
  • supports json
  • supports nested objects
  • no dependencies outside of python's library (only pytest for developing)
  • ability to add methods to control serializing and deserializing

Drawbacks

  • objects like tuples are automatically turned into lists
  • only supports json right now
  • can't handle circular references
  • if an object has references in many places, it will be present in the json repeatedly and after deserializing will be separate objects
  • Because of this, it cannot handle linked lists or similar interconnected data structures well
  • stores __dict__ of the object, so classes using __slots__ will likely require overriding the serialize method and deserialize classmethod.
  • Because it needs to create the object and then copy over all the values of __dict__, it doesn't know the arguments used in __init__. Thus if the class requires arguments in __init__, the object will be created with __new__ which avoids calling __init__. However, if __init__ can take zero arguments, it will be called. A warning will be emitted if __init__ is not called.

How to use

Extend Serializable

class A(Serializable):
    ...

or use the make_serializable decorator

@make_serializable
class A:
    ...

serialize using

serialize(object_to_serialize)

and deserialize using

deserialize(stringified_object)

Custom serializing

In the case that the standard method doesn't cut it, it is possible to add custom serializing and deserializing methods to a class

@make_serializable
class A:
    def __init__(self, x):
        self.x = x

    def serialize(self) -> dict:
        return {'x': self.x}

    @classmethod
    def deserialize(cls, data: dict) -> 'A':
        return A(data['x'])

Future

Things to possibly add:

  • other data formats like xml or the like
  • support for objects with circular references

Metadata

Release files for easy-serialize 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easy-serialize 0.0.3
File Size Uploaded
easy-serialize-0.0.3.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easy-serialize 0.0.3
File Interpreter ABI Platform
easy_serialize-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / easy-serialize-0.0.3.tar.gz

Download URL easy-serialize-0.0.3.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
030c0d0af36380779514a74fa3e8be20e8562d3790c3db30c78d7286c38dcf18
BLAKE2b-256 checksum
How to use checksums
ea877ba2938b49569f07922b19f7b79c0c8b8befc95091b5a3bc51bccd826023
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release files / easy_serialize-0.0.3-py3-none-any.whl

Download URL easy_serialize-0.0.3-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
237ef1087f4dce935162f52dc8e1adccc6ac5ed10216e0c93d7dacdbea50c4aa
BLAKE2b-256 checksum
How to use checksums
36b0fb1af4eee5973329ce55ec0d530b91d9ddda91c4040a909c954fa006ba82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

1 release file

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