Skip to main content

Warlock 🧙‍♀️

Create self-validating Python objects using JSON schema.

PyPI PyPI - Python Version PyPI - Downloads

Build Status Coverage Status GitHub commits since latest release (branch)

Package management: poetry Code Style Black

Installation

Warlock is available on PyPI:

pip install warlock

Usage

  1. Create your schema

    >>> schema = {
        'name': 'Country',
        'properties': {
            'name': {'type': 'string'},
            'abbreviation': {'type': 'string'},
            'population': {'type': 'integer'},
        },
        'additionalProperties': False,
    }
    
  2. Create a model

    >>> import warlock
    >>> Country = warlock.model_factory(schema)
    
  3. Create an object using your model

    >>> sweden = Country(name='Sweden', abbreviation='SE')
    
  4. 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'
    
  5. 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)

Source distribution for warlock 2.1.0
File Size Uploaded
warlock-2.1.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for warlock 2.1.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page