A dead-simple utility that validates if object has a certain structure.
Project description
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_keys
are those keys that are required in theschema
, but not found indata
.additional_keys
are those keys present indata
, but not required by theschema
.- Nested keys are represented with "dot" notation -
profile.email
,tokens.jwt
, etc.
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
Close
Hashes for simple_schema_validator-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d15fdb664e50ee085b0e942d38049aec4ffcb3c3d87f263063ba641e519f971 |
|
MD5 | df31a894ca79688708745a902fe33a6a |
|
BLAKE2b-256 | d260e15524b3e9344ca7fd82a5fbbccddd00fce1c9829faed523f0e37a85c204 |
Close
Hashes for simple_schema_validator-0.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb2bd5dbe591426566ce6e13fe9397ca04fb90f5c8bd589fab687a3bba2dc445 |
|
MD5 | dcf30dfa5a78777503946adeb76b3d62 |
|
BLAKE2b-256 | a365de1c18fbc487d79229bea7b725dc4398c8a8965c689a20c21185bbafea9b |