Skip to main content

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 the schema, but not found in data.
  • additional_keys are those keys present in data, but not required by the schema.
  • Nested keys are represented with "dot" notation - profile.email, tokens.jwt, etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_schema_validator-0.0.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

simple_schema_validator-0.0.4-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2 Python 3

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

Hashes for simple_schema_validator-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7d15fdb664e50ee085b0e942d38049aec4ffcb3c3d87f263063ba641e519f971
MD5 df31a894ca79688708745a902fe33a6a
BLAKE2b-256 d260e15524b3e9344ca7fd82a5fbbccddd00fce1c9829faed523f0e37a85c204

See more details on using hashes here.

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

Hashes for simple_schema_validator-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cb2bd5dbe591426566ce6e13fe9397ca04fb90f5c8bd589fab687a3bba2dc445
MD5 dcf30dfa5a78777503946adeb76b3d62
BLAKE2b-256 a365de1c18fbc487d79229bea7b725dc4398c8a8965c689a20c21185bbafea9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page