Simple schema validator
A dead-simple utility that validates if object has a certain structure. Used in some of our projects.
pip install simple_schema_validator
An example:
Lets say we have an API that returns the following data:
{
"user": 1,
"profile": {
"email": "some@user.com",
"name": "Some User",
"age": 20
},
"tokens": {
"jwt": "...",
"refresh": "...",
"firebase": "...",
}
}
And we are writing a simple integration test, that wants to assure the response has a certain structure.
Then we can use the schema validator like so:
from simple_schema_validator import schema_validator
data = get_data_from_api()
schema = {
'user': Any,
'profile': {
'email': Any,
'name': Any,
'age': Any
},
'tokens': {
'jwt': Any,
'refresh': Any,
'firebase': Any
}
}
result = schema_validator(schema, data)
if not result:
print(f'Schema not valid. Missing: {result.missing_keys}, additional: {result.additional_keys}')
missing_keysare those keys that are required in theschema, but not found indata.additional_keysare those keys present indata, but not required by theschema.- Nested keys are represented with "dot" notation -
profile.email,tokens.jwt, etc.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_schema_validator-0.0.4.tar.gz.
File metadata
- Download URL: simple_schema_validator-0.0.4.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d15fdb664e50ee085b0e942d38049aec4ffcb3c3d87f263063ba641e519f971
|
|
| MD5 |
df31a894ca79688708745a902fe33a6a
|
|
| BLAKE2b-256 |
d260e15524b3e9344ca7fd82a5fbbccddd00fce1c9829faed523f0e37a85c204
|
File details
Details for the file simple_schema_validator-0.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: simple_schema_validator-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb2bd5dbe591426566ce6e13fe9397ca04fb90f5c8bd589fab687a3bba2dc445
|
|
| MD5 |
dcf30dfa5a78777503946adeb76b3d62
|
|
| BLAKE2b-256 |
a365de1c18fbc487d79229bea7b725dc4398c8a8965c689a20c21185bbafea9b
|