Python object model built on JSON schema and JSON patch.
Project description
Warlock 🧙♀️
Create self-validating Python objects using JSON schema.
Installation
Warlock is available on PyPI:
pip install warlock
Usage
-
Create your schema
>>> schema = { 'name': 'Country', 'properties': { 'name': {'type': 'string'}, 'abbreviation': {'type': 'string'}, 'population': {'type': 'integer'}, }, 'additionalProperties': False, }
-
Create a model
>>> import warlock >>> Country = warlock.model_factory(schema)
-
Create an object using your model
>>> sweden = Country(name='Sweden', abbreviation='SE')
-
Let the object validate itself
>>> sweden.name = 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "warlock/core.py", line 53, in __setattr__ raise InvalidOperation(msg) warlock.core.InvalidOperation: Unable to set 'name' to '5' >>> sweden.overlord = 'Bears' Traceback (most recent call last): File "<stdin>", line 1, in <module> File "warlock/core.py", line 53, in __setattr__ raise InvalidOperation(msg) warlock.core.InvalidOperation: Unable to set 'overlord' to 'Bears'
-
Generate a JSON Patch document to track changes
>>> sweden.population=9453000 >>> sweden.patch '[{"path": "/population", "value": 9453000, "op": "add"}]'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
warlock-2.1.0.tar.gz
(8.0 kB
view details)
Built Distribution
warlock-2.1.0-py3-none-any.whl
(10.3 kB
view details)
File details
Details for the file warlock-2.1.0.tar.gz
.
File metadata
- Download URL: warlock-2.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
82319ba017341e7fcdc81efc2be9dd2f8237a0da07c71476b5425651b317b1c9
|
|
MD5 |
956e48e3edd9be15c9291936a0f7be7e
|
|
BLAKE2b-256 |
29c23ba4daeddd47f1cfdbc703048cbee27bcbc50535261a2bbe36412565f3c9
|
File details
Details for the file warlock-2.1.0-py3-none-any.whl
.
File metadata
- Download URL: warlock-2.1.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
55cb5ad3399083724f1bfbfef4234a11fbacfc78bf2b9c4d0c18b6e203cf78fe
|
|
MD5 |
3a7b51007574a4e5b1a22f5b5f409f99
|
|
BLAKE2b-256 |
534b8b3a3ae43afd4f7e4eebd86b53924d5271f84857ca38161ca502d0891caa
|