Skip to main content

A library for mapping dictionaries to Python objects

Project description

Sample usage

With dicty you can easily describe your data model and then use it to encode/decode JSON objects. It supports data validataion, optional parameters, default values, nested objects and so on.

import dicty


class MyDoc(dicty.DictObject):
    prop1 = dicty.StringField()
    prop2 = dicty.IntegerField()

# Regular constructor
doc = MyDoc(prop1='foo', prop2=123)
print doc.prop1     # you can access values as attributes
print doc['prop2']  # as well as dictionary items

print json.dumps(doc)
print json.dumps(doc.jsonify()) # Jsonify will clean and validate output data

# Create instance from dictionary
doc = MyDoc.fromjson({'prop1': 'foo', 'prop2': 123})

# would raise dicty.FieldError here
doc = MyDoc.fromjson({'prop1': 123, 'prop2': 123})

Nested Objects

import dicty


class Foo(dicty.DictObject):
    class Bar(dicty.DictObject):
        prop = dicty.StringField()

    bar = dicty.TypedObjectField(Bar)

obj = Foo()
obj.bar.prop = 123
print obj # {'bar': {'prop': 123}}

Project details


Release history Release notifications

History Node

0.1.1

This version
History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
dicty-0.1.tar.gz (3.9 kB) Copy SHA256 hash SHA256 Source None Jun 7, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page