You may use schema (PyPi Link)

schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.

from schema import Schema, And, Use, Optional, SchemaError

def check(conf_schema, conf):
    try:
        conf_schema.validate(conf)
        return True
    except SchemaError:
        return False

conf_schema = Schema({
    'version': And(Use(int)),
    'info': {
        'conf_one': And(Use(float)),
        'conf_two': And(Use(str)),
        'conf_three': And(Use(bool)),
        Optional('optional_conf'): And(Use(str))
    }
})

conf = {
    'version': 1,
    'info': {
        'conf_one': 2.5,
        'conf_two': 'foo',
        'conf_three': False,
        'optional_conf': 'bar'
    }
}

print(check(conf_schema, conf))
Answer from Danil Speransky on Stack Overflow
🌐
PyPI
pypi.org › project › schema
schema · PyPI
schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.
      » pip install schema
    
Published   Oct 11, 2025
Version   0.7.8
🌐
Hacker News
news.ycombinator.com › item
Hands down, my favorite new library is schema: https://pypi.python.org/pypi/sche... | Hacker News
December 29, 2015 - https://pypi.python.org/pypi/schema · Here's a schema I use in production, see how readable it makes the parameters of the API and how quick all the validation and normalization is:
Discussions

validation - How to validate structure (or schema) of dictionary in Python? - Stack Overflow
schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types. More on stackoverflow.com
🌐 stackoverflow.com
Python library for automating data normalisation, schema creation and loading to db
Damn this looks amazing! I will try some personal projects with it! More on reddit.com
🌐 r/dataengineering
115
249
June 26, 2023
Python Schema Or() - Stack Overflow
I was wondering if anyone has used the pypi module Schema and could help me? So I have a schema which I want to validate and I'm using the Or method which is nice because it allows you to have eith... More on stackoverflow.com
🌐 stackoverflow.com
best way to validating csv file in python
It depends on your needs. If it's a one-off, then it's often easiest to simply hard-code the field constraints (types, case, length, min/max values, unknown values, etc) - and iterate through the file record by record checking whatever you'd like. However, if you have a variety of files, or if the constraints are liable to change fairly often then using something like Validictory with a separate validation config file may be a better way to go. The python package Validictory uses the json schema format, which is cool, but unlike json a csv will return all fields in a string format. So, you need to tweak the approach a bit to handle type and minimum & maximum field length. Here's a generic csv validation tool I wrote to use json schema against csv files. More on reddit.com
🌐 r/Python
21
5
August 25, 2017
🌐
schemaorg
openschemas.github.io › schemaorg
Schemaorg Python - OpenSchemas
We can first read in our specification. This is production and provided with the python library. spec = Schema("SoftwareSourceCode") Specification base set to http://www.schema.org Using Version 5.0 Found http://www.schema.org/SoftwareSourceCode SoftwareSourceCode: found 104 properties ·
Top answer
1 of 10
76

You may use schema (PyPi Link)

schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.

from schema import Schema, And, Use, Optional, SchemaError

def check(conf_schema, conf):
    try:
        conf_schema.validate(conf)
        return True
    except SchemaError:
        return False

conf_schema = Schema({
    'version': And(Use(int)),
    'info': {
        'conf_one': And(Use(float)),
        'conf_two': And(Use(str)),
        'conf_three': And(Use(bool)),
        Optional('optional_conf'): And(Use(str))
    }
})

conf = {
    'version': 1,
    'info': {
        'conf_one': 2.5,
        'conf_two': 'foo',
        'conf_three': False,
        'optional_conf': 'bar'
    }
}

print(check(conf_schema, conf))
2 of 10
36

Use Pydantic!

Pydantic enforces type hints at runtime, and provides user friendly errors when data is invalid. Define how data should be in pure, canonical python; validate it with pydantic, as simple as that:

from pydantic import BaseModel


class Info(BaseModel):
    conf_one: float
    conf_two: str
    conf_three: bool

    class Config:
        extra = 'forbid'


class ConfStructure(BaseModel):
    version: int
    info: Info

If validation fails pydantic will raise an error with a breakdown of what was wrong:

my_conf_wrong = {
    'version': 1,

    'info': {
        'conf_one': 2.5,
        'conf_two': 'foo',
        'conf_three': False,
        'optional_conf': 'bar'
    }
}

my_conf_right = {
    'version': 10,

    'info': {
        'conf_one': 14.5,
        'conf_two': 'something',
        'conf_three': False
    }
}

model = ConfStructure(**my_conf_right)
print(model.dict())
# {'version': 10, 'info': {'conf_one': 14.5, 'conf_two': 'something', 'conf_three': False}}

res = ConfStructure(**my_conf_wrong)
# pydantic.error_wrappers.ValidationError: 1 validation error for ConfStructure
#     info -> optional_conf
# extra fields not permitted (type=value_error.extra)
🌐
GitHub
github.com › python-jsonschema › jsonschema
GitHub - python-jsonschema/jsonschema: An implementation of the JSON Schema specification for Python · GitHub
>>> from jsonschema import validate >>> # A sample schema, like what we'd get from json.load() >>> schema = { ... "type" : "object", ... "properties" : { ... "price" : {"type" : "number"}, ... "name" : {"type" : "string"}, ... }, ... } >>> # If no exception is raised by validate(), the instance is valid. >>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema) >>> validate( ... instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema, ...
Starred by 4.9K users
Forked by 610 users
Languages   Python 99.8% | TypeScript 0.2%
🌐
Reddit
reddit.com › r/dataengineering › python library for automating data normalisation, schema creation and loading to db
r/dataengineering on Reddit: Python library for automating data normalisation, schema creation and loading to db
June 26, 2023 -

Hey Data Engineers!,

For the past 2 years I've been working on a library to automate the most tedious part of my own work - data loading, normalisation, typing, schema creation, retries, ddl generation, self deployment, schema evolution... basically, as you build better and better pipelines you will want more and more.

The value proposition is to automate the tedious work you do, so you can focus on better things.

So dlt is a library where in the easiest form, you shoot response.json() json at a function and it auto manages the typing normalisation and loading.

In its most complex form, you can do almost anything you can want, from memory management, multithreading, extraction DAGs, etc.

The library is in use with early adopters, and we are now working on expanding our feature set to accommodate the larger community.

Feedback is very welcome and so are requests for features or destinations.

The library is open source and will forever be open source. We will not gate any features for the sake of monetisation - instead we will take a more kafka/confluent approach where the eventual paid offering would be supportive not competing.

Here are our product principles and docs page and our pypi page.

I know lots of you are jaded and fed up with toy technologies - this is not a toy tech, it's purpose made for productivity and sanity.

Edit: Well this blew up! Join our growing slack community on dlthub.com

Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › introduction-to-python-jsonschema
Introduction to Python jsonschema - GeeksforGeeks
July 23, 2025 - A schema defines the structure and constraints for JSON data, ensuring that the data adheres to specific rules and formats. The jsonschema library allows developers to define these rules and validate JSON data accordingly. To install the jsonschema, ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › overview › azure › schemaregistry-readme
Azure Schema Registry client library for Python | Microsoft Learn
A client library to register and retrieve schemas and their respective properties. An JSON schema-based encoder capable of encoding and decoding payloads containing Schema Registry schema identifiers, corresponding to JSON schemas used for ...
🌐
Google Cloud
cloud.google.com › python › documentation › reference › class schema (0.13.12)
Class Schema (0.13.12) | Python client library | Google Cloud
Python · Documentation · Reference ... Schema(mapping=None, *, ignore_unknown_fields=False, **kwargs) Defines the structure and layout of a type of document data....
🌐
GitHub
github.com › frictionlessdata › tableschema-py
GitHub - frictionlessdata/tableschema-py: A Python library for working with Table Schema. · GitHub
A Python library for working with Table Schema. Contribute to frictionlessdata/tableschema-py development by creating an account on GitHub.
Starred by 266 users
Forked by 39 users
Languages   Python 99.4% | Makefile 0.6%
🌐
PyPI
pypi.org › project › python-schema
python-schema
October 30, 2019 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Hitchdev
hitchdev.com › strictyaml › why-not › python-schema
Why not use Python's schema library (or similar) for validation? - HitchDev
Python's 'schema' (as well as similar libraries) can also be used to validate the structure of objects.
🌐
Horejsek
horejsek.github.io › python-fastjsonschema
Fast JSON schema for Python — fastjsonschema documentation
Support only for Python 3.3 and higher. fastjsonschema implements validation of JSON documents by JSON schema. The library implements JSON schema drafts 04, 06, and 07. The main purpose is to have a really fast implementation.
🌐
jsonschema
python-jsonschema.readthedocs.io
jsonschema 4.26.0 documentation
PyPI version Supported Python versions Build status ReadTheDocs status pre-commit.ci status Zenodo DOI jsonschema is an implementation of the JSON Schema specification for Python. It can also be us...
🌐
GitHub
github.com › keleshev › schema
GitHub - keleshev/schema: Schema validation just got Pythonic · GitHub
schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.
Starred by 2.9K users
Forked by 217 users
Languages   Python
🌐
GitHub
github.com › b3j0f › schema
GitHub - b3j0f/schema: Pyhton schema library · GitHub
This library provides an abstraction layer for manipulating schema from several languages. The abstraction layer is a python object which can validate data (properties to validate are object attributes or dictionary items) and be dumped into ...
Author   b3j0f
🌐
Snyk
snyk.io › advisor › python packages › schema
schema - Python Package Health Analysis | Snyk
schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.
🌐
PyPI
pypi.org › project › schema › 0.3.1
schema 0.3.1
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser