A library for trivial structure validation
Project description
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
}
}
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
Built Distribution
File details
Details for the file trivval-1.1.2.tar.gz
.
File metadata
- Download URL: trivval-1.1.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50267a2542209a9de73a4c289fa03597d339f53f5379c17ac8e03a18644d71e |
|
MD5 | 821097b70623ecfa29c8c1e5c0d873d8 |
|
BLAKE2b-256 | aae0aefb77b14f446c9c30ec59238f260452b2790d736d4255a61e3db89c13c2 |
File details
Details for the file trivval-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: trivval-1.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc2cb572498b60eae8a0b93db96b1a5a553e52562e6425d7bae22751bccb74f1 |
|
MD5 | 2e7a90cb3af981f4ba497fc267a51649 |
|
BLAKE2b-256 | c7d9477d46425e966e2ecc9020e1b2ce1008afb84bb09b1ba2ed2aa3776f3c69 |