Skip to main content

Python serialization for adults

Project description

Camel is a library that lets you describe how to serialize your objects to YAML — and refuses to serialize them if you don’t.

Quick example:

from camel import Camel, CamelRegistry

class DieRoll(tuple):
    def __new__(cls, a, b):
        return tuple.__new__(cls, [a, b])

    def __repr__(self):
        return "DieRoll(%s,%s)" % self

reg = CamelRegistry()

@reg.dumper(DieRoll, u'roll', version=None)
def _dump_dice(data):
    return u"{}d{}".format(*data)

@reg.loader(u'roll', version=None)
def _load_dice(data, version):
    a, _, b = data.partition(u'd')
    return DieRoll(int(a), int(b))

value = DieRoll(3, 6)
camel = Camel([reg])
print(camel.dump(value))

# !roll 3d6
# ...

Docs: http://camel.readthedocs.org/en/latest/

GitHub: https://github.com/eevee/camel

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for camel, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size camel-0.1.2-py2.py3-none-any.whl (23.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size camel-0.1.2.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

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