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': None,
  'profile': {
    'email': None,
    'name': None,
    'age': None
  },
  'tokens': {
    'jwt': None,
    'refresh': None,
    'firebase': None
  }
}

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

Uploaded Source

Built Distribution

simple_schema_validator-0.0.2-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.2.tar.gz.

File metadata

  • Download URL: simple_schema_validator-0.0.2.tar.gz
  • Upload date:
  • Size: 4.2 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.2.tar.gz
Algorithm Hash digest
SHA256 3820ac5debd96e477c3b510465e5b71cd2a451549e83bf02033fa13b13188940
MD5 24b3dfe204ea8f7f242aa93f56085dd0
BLAKE2b-256 f4be3deebf051072db449bff4a8c4df20bef4e2a1aafde7005091e5a9f291ec3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_schema_validator-0.0.2-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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b42bc05c094437a98f77ac840c8f42bc1bb321aba9f6d494ba014fca4d8abd80
MD5 4f7cec2aa8c1b94406ddf669829b0d22
BLAKE2b-256 26e4de3a6df5a78d7f696f52b8bed3309a8370fa293750785c8a69bf12d66ef3

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