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
  }
}

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 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.3.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

simple_schema_validator-0.0.3-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file simple_schema_validator-0.0.3.tar.gz.

File metadata

  • Download URL: simple_schema_validator-0.0.3.tar.gz
  • Upload date:
  • Size: 4.3 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.3.tar.gz
Algorithm Hash digest
SHA256 63815dfbf6eea8e7f2dc25d04f1a2107b1b769acd0f2b67021b1a2e60576c991
MD5 42b81b0ff59148ce542564e546c71cc6
BLAKE2b-256 86ad7f125cbd593fc069453ab85710401e8424a5553dc82610f355e41787e978

See more details on using hashes here.

File details

Details for the file simple_schema_validator-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: simple_schema_validator-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.9 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.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7641a1250f18bff791f5f0e53b782b5c3a9dc0eb8af692b7955d266f43c7847e
MD5 a0bea4fcc009bdc3c5dd077b5712d44d
BLAKE2b-256 57be825d041a04d987aa22f98b874b2b2faf4347a6ad71a6c882bb29b717dbd0

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