Json schema Model
Project description
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() >>> obj.bar.add(zaz="qux") {'zaz': 'qux'} >>> assert obj == {'foo': 'bar', 'bar': [{'zaz': 'qux'}]} # You can access via attribute or via dict like interface >>> obj["bar"][0].zaz 'qux' # Array have a special get_or_create() method # to avoid dupplicates within an array >>> obj.bar.get_or_create(zaz="xuq") {'zaz': 'xuq'} >>> obj.bar [{'zaz': 'qux'}, {'zaz': 'xuq'}] >>> obj.bar.get_or_create(zaz="xuq") {'zaz': 'xuq'} >>> obj.bar [{'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.
Source Distribution
jsonschema-model-1.3.0.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for jsonschema_model-1.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f1da17527672995cefbc17e6248edeca66ef6bbe6b7f8a096d9470db4ba0fb8 |
|
MD5 | 3ef654123fc74c67acac4335e2b40a5b |
|
BLAKE2b-256 | d7390a571ac1c64d88ba157ab79e6cd60e3d7703a9a07b4a9db908503157261b |