Skip to main content

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.

Metadata

Release files for simple-schema-validator 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-schema-validator 0.0.3
File Size Uploaded
simple_schema_validator-0.0.3.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-schema-validator 0.0.3
File Interpreter ABI Platform
simple_schema_validator-0.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 9.1 kB

Release files / simple_schema_validator-0.0.3.tar.gz

Download URL simple_schema_validator-0.0.3.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
63815dfbf6eea8e7f2dc25d04f1a2107b1b769acd0f2b67021b1a2e60576c991
BLAKE2b-256 checksum
How to use checksums
86ad7f125cbd593fc069453ab85710401e8424a5553dc82610f355e41787e978
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / simple_schema_validator-0.0.3-py2.py3-none-any.whl

Download URL simple_schema_validator-0.0.3-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7641a1250f18bff791f5f0e53b782b5c3a9dc0eb8af692b7955d266f43c7847e
BLAKE2b-256 checksum
How to use checksums
57be825d041a04d987aa22f98b874b2b2faf4347a6ad71a6c882bb29b717dbd0
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page