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"}]'
Release files for warlock 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| warlock-2.1.0.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| warlock-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / warlock-2.1.0.tar.gz
| Download URL | warlock-2.1.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
82319ba017341e7fcdc81efc2be9dd2f8237a0da07c71476b5425651b317b1c9
|
|
BLAKE2b-256 checksum How to use checksums |
29c23ba4daeddd47f1cfdbc703048cbee27bcbc50535261a2bbe36412565f3c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.22
|
Release files / warlock-2.1.0-py3-none-any.whl
| Download URL | warlock-2.1.0-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
55cb5ad3399083724f1bfbfef4234a11fbacfc78bf2b9c4d0c18b6e203cf78fe
|
|
BLAKE2b-256 checksum How to use checksums |
534b8b3a3ae43afd4f7e4eebd86b53924d5271f84857ca38161ca502d0891caa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.22
|