Skip to main content

Json schema Model

Project description

Build status Downloads Latest Version License

Build python objects using JSON schemas:

>>> import jsonschema_model
>>> Model = jsonschema_model.model_factory({
...    "name": "Model",
...    "properties": {
...        "foo": {"type": "string"},
...        "bar": {"type": "array", "items": {
...            "type": "object",
...            "name": "Bar",
...            "properties": {
...                "zaz": {"type": "string"},
...            },
...        }},
...    }})

# Simple object creation
>>> obj = Model(foo="bar")
>>> assert obj == {"foo": "bar"}

# Nested and array are implemented
# HINT: Use add() instead of append()
{'zaz': 'qux'}
>>> assert obj == {'foo': 'bar', 'bar': [{'zaz': 'qux'}]}

# You can access via attribute or via dict like interface
>>> obj["bar"][0].zaz

# Array have a special get_or_create() method
# to avoid dupplicates within an array
{'zaz': 'xuq'}
[{'zaz': 'qux'}, {'zaz': 'xuq'}]
{'zaz': 'xuq'}
[{'zaz': 'qux'}, {'zaz': 'xuq'}]

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 jsonschema-model, version 1.3.0
Filename, size File type Python version Upload date Hashes
Filename, size jsonschema_model-1.3.0-py2.py3-none-any.whl (4.0 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size jsonschema-model-1.3.0.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page