Skip to main content

Trivial validation - when the full power of the JSON Schema is not needed

This library provides a simplistic way to validate a dictionary against something resembling a schema - a dictionary describing the desired data structure by example.

The main entry point is the validate() function, but the various validate_*() functions may be invoked directly with appropriate arguments.

The schema used for validation is a dictionary (the top-level object must be a dictionary). For the present, the keys may only be strings. A special case of a dictionary with a single key * means any value for a key will be accepted. Otherwise, all keys with names not starting with a ? character are mandatory, and any keys with names starting with a ? character are optional.

The dictionary values may be any of:

  • a Python type signifying that the value must be an instance thereof
  • a single-element list signifying that the value must be a list with all the elements validated by the same rules as a dictionary value (i.e. one of a Python type, a single-element list, a set, or a dictionary)
  • a set signifying that the value must be exactly equal to one of the set elements, i.e. an enumeration of the allowed values
  • a dictionary with the same semantics as described above

For example, the following schema:

{
    "name": str,
    "id": int,
    "address": [str],
    "preferences": {
        "meal": set(("breakfast", "lunch", "brunch")),
        "colors": [{
            "name": str,
            "intensity": set(["dark", "light"])
        }]
    },
    "possessions": {
        "*": int
    }
}

...may be used to validate the following dictionary:

{
    "name": "A. N. Nymous",
    "id": 13,
    "address": [
        "42 Nowhere Circle",
        "Notown-at-all",
        "Unnamed territory"
    ],
    "preferences": {
        "meal": "brunch",
        "colors": [
            {"name": "blue", "intensity": "light"},
            {"name": "green", "intensity": "dark"}
        ]
    },
    "possessions": {
        "pencil": 4,
        "paper": 0
    }
}

Metadata

Release files for trivval 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trivval 1.1.2
File Size Uploaded
trivval-1.1.2.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trivval 1.1.2
File Interpreter ABI Platform
trivval-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / trivval-1.1.2.tar.gz

Download URL trivval-1.1.2.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c50267a2542209a9de73a4c289fa03597d339f53f5379c17ac8e03a18644d71e
BLAKE2b-256 checksum
How to use checksums
aae0aefb77b14f446c9c30ec59238f260452b2790d736d4255a61e3db89c13c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / trivval-1.1.2-py3-none-any.whl

Download URL trivval-1.1.2-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc2cb572498b60eae8a0b93db96b1a5a553e52562e6425d7bae22751bccb74f1
BLAKE2b-256 checksum
How to use checksums
c7d9477d46425e966e2ecc9020e1b2ce1008afb84bb09b1ba2ed2aa3776f3c69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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