Skip to main content

Universal Python serializer

Project description


Universal converter of all things Python to a dict. So it can be serialized to JSON.


pip install d-serialize


from d_serialize import d_serialize
from objects import SomeObject

some_object = SomeObject()
json_values = d_serialize(some_object)

Usage in Flask

from d_serialize import d_serialize
from flask import jsonify
from objects import SomeObject

def a_route():
    some_object = SomeObject()
    json_values = d_serialize(some_object)
    return jsonify(json_values)

d_serialize will enumerate all public properties of your object (or dict) and convert them to a JSON allowable type. IE:

list, dictionary, string, float, integer or boolean.

Any property that is not one of these types will be converted to a string. set and tuple will be converted to list.

Dictionary and list properties will be followed to ensure all child objects and values are also converted.

Methods and private properties (starting with _) are not enumerated.

Any property or attribute that raises an exception will be excluded or have a None value.


Converting a Class instance.

        class TestObject:
            number_value = 1
            float_value = 1.1

            def dont_call_me(self):
                """return self.number_value"""

        # dict(number_value=1, float_value=1.1)

Release History

1.0.0 First version of this wondrous package. 1.0.1 Check for None when serializing and return None rather than 'None'. Exceptions on getattr return None for value.

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

d-serialize-1.0.1.tar.gz (4.6 kB view hashes)

Uploaded source

Built Distribution

d_serialize-1.0.1-py2.py3-none-any.whl (3.8 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page