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
}
}
valid, missing_keys, additional_keys = schema_validator(schema, data)
assert valid, f'Response not valid, missing: {missing_keys}, additional: {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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63815dfbf6eea8e7f2dc25d04f1a2107b1b769acd0f2b67021b1a2e60576c991 |
|
MD5 | 42b81b0ff59148ce542564e546c71cc6 |
|
BLAKE2b-256 | 86ad7f125cbd593fc069453ab85710401e8424a5553dc82610f355e41787e978 |
Close
Hashes for simple_schema_validator-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7641a1250f18bff791f5f0e53b782b5c3a9dc0eb8af692b7955d266f43c7847e |
|
MD5 | a0bea4fcc009bdc3c5dd077b5712d44d |
|
BLAKE2b-256 | 57be825d041a04d987aa22f98b874b2b2faf4347a6ad71a6c882bb29b717dbd0 |