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 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
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
July 2, 2023
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
September 1, 2017
🌐
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
July 2, 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

🌐
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%
🌐
Pydantic
docs.pydantic.dev › latest
Welcome to Pydantic - Pydantic Validation
Powered by type hints — with Pydantic, schema validation and serialization are controlled by type annotations; less to learn, less code to write, and integration with your IDE and static analysis tools. Learn more… · Speed — Pydantic's core validation logic is written in Rust. As a result, Pydantic is among the fastest data validation libraries for Python...
🌐
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, ...
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › validate
Schema Validation - jsonschema 4.26.1.dev25+gad0a1b301 documentation
Most of the documentation for this package assumes you’re familiar with the fundamentals of writing JSON schemas themselves, and focuses on how this library helps you validate with them in Python.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › overview › azure › schemaregistry-readme
Azure Schema Registry client library for Python | Microsoft Learn
September 19, 2024 - 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 ...
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
Python + JSON Schema · GitHub
JSON Schema implementation and surrounding tooling for Python - Python + JSON Schema
🌐
GitHub
github.com › vajol › python-data-engineering-resources › blob › main › resources › data-schema-validation.md
python-data-engineering-resources/resources/data-schema-validation.md at main · vajol/python-data-engineering-resources
A handpicked collection of resources for Python developers in data engineering, machine learning, and AI. Inside, you'll discover a neatly arranged selection of frameworks, libraries, and tools crucial for machine learning, ETL, ORM, data/schema validation, database migration, and more, all focused on Python.
Author   vajol
🌐
Pydantic
docs.pydantic.dev › latest › concepts › json_schema
JSON Schema - Pydantic Validation
Pydantic allows automatic creation and customization of JSON schemas from models.
🌐
GitHub
github.com › sissaschool › xmlschema
GitHub - sissaschool/xmlschema: XML Schema validator and data conversion library for Python
XML Schema validator and data conversion library for Python - sissaschool/xmlschema
Starred by 473 users
Forked by 81 users
Languages   Python 99.9% | Jinja 0.1% | Python 99.9% | Jinja 0.1%
🌐
Medium
medium.com › geekculture › data-validation-an-introduction-to-schemas-using-cerberus-9c0a93a1de70
Data Validation: An Introduction to Schemas in Python using Cerberus | by Maxine Attobrah | Geek Culture | Medium
January 4, 2023 - Data validation is an important process when dealing with data. Accelerate data cleaning/preprocessing by creating schemas using Cerberus Python library
🌐
GitHub
github.com › grundic › awesome-python-models
GitHub - grundic/awesome-python-models: A curated list of awesome Python libraries, which implement models, schemas, serializers/deserializers, ODM's/ORM's, Active Records or similar patterns.
jsonschema - jsonschema is an implementation of JSON Schema for Python (supporting 2.7+ including Python 3). pyschemes - PySchemes is a library for validating data structures in Python.
Starred by 167 users
Forked by 9 users
🌐
Anaconda.org
anaconda.org › conda-forge › schema
Schema - conda install
schema is a Python library for validating 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.
🌐
JSON Schema
json-schema.org › implementations
JSON Schema - Tools
Toolings below are written in different languages, and support part, or all, of at least one recent version of the specification · Listing does not signify a recommendation or endorsement of any kind
🌐
Code Like A Girl
code.likeagirl.io › python-schema-validation-with-marshmallow-d4c3b9752655
Python Schema Validation with Marshmallow | by Python Code Nemesis | Code Like A Girl
February 27, 2023 - Overall, schema validation is an important tool for ensuring the quality and consistency of data in Python applications. It can help to prevent errors, improve security, and make it easier to work with the data. You can use the Marshmallow library in Python to validate database schema by defining a schema class for each table in your database and using the Marshmallow validate method to validate user input against the schema.
🌐
Libhunt
python.libhunt.com › schema-alternatives
schema Alternatives - Python Data Validation | LibHunt
February 27, 2025 - Alternatively, view schema alternatives based on common mentions on social networks and blogs. ... InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now. ... Python Data Structures for Humans™. ... CONTRIBUTIONS ONLY: Voluptuous, despite the name, is a Python data validation library...