pdschema
Validate pandas DataFrames against column contracts. Types, nullability, and per-cell checks. No cleaning or transforms.
Python 3.12+.
pip install pdschema
Quick example
import pandas as pd
from pdschema import Column, IsNonEmptyString, IsPositive, Range, Schema
df = pd.DataFrame(
{
"idx": [1, 2, 3],
"name": ["Alice", "Bob", "Charlie"],
"age": [25, 30, 35],
"score": [85.5, 92.0, 78.5],
}
)
schema = Schema(
[
Column("idx", int, nullable=False),
Column("name", str, nullable=False, validators=[IsNonEmptyString()]),
Column("age", int, validators=[IsPositive()]),
Column("score", float, validators=[Range(0, 100)]),
]
)
schema.validate(df)
Features
Two ways to define schemas — pass a list of Column objects, or declare them as class attributes:
class People(Schema):
idx = Column(dtype=int, nullable=False)
name = Column(dtype=str, nullable=False, validators=[IsNonEmptyString])
age = Column(dtype=int, validators=[IsPositive])
score = Column(dtype=float, validators=[Range(0, 100)])
Schema inference — start from a trusted DataFrame and tighten from there:
draft = Schema.infer_schema(df)
Strict mode — reject DataFrames with columns not in the schema:
Schema([Column("idx", int)], strict=True).validate(df)
Built-in validators — IsNonEmptyString, IsPositive, Range, Min, Max, GreaterThan, LessThan, Choice, Length, and more. All validators are extensible via the Validator abstract base class.
@pdfunction decorator — validate DataFrame inputs and outputs at function boundaries:
@pdfunction(arguments={"df": schema}, outputs={"result": output_schema})
def transform(df: pd.DataFrame) -> dict[str, pd.DataFrame]:
...
Clear error reporting — SchemaValidationError (also a ValueError) with one line per problem:
Schema validation failed:
Unexpected columns: ['extra']
Validation failed in 'age' at index 0: -1 (IsPositive)
Full walkthrough: docs/user/quickstart.md.
MIT. See LICENSE.
Metadata
Release files for pdschema 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pdschema-0.2.1.tar.gz | 9.9 kB | Without provenance | Details for pdschema-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pdschema-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for pdschema-0.2.1-py3-none-any.whl |
Total release size: 21.2 kB
Release files / pdschema-0.2.1.tar.gz
| Download URL | pdschema-0.2.1.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f04982f5aa8e5e27b0baff1cdd8d36440e451bb9a4693c027757cee757667860
|
|
BLAKE2b-256 checksum How to use checksums |
88b48276e03312d3d38243895ce29e12568d47c5604174d5294be18dfb517b26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pdschema-0.2.1-py3-none-any.whl
| Download URL | pdschema-0.2.1-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b83bfab1eab7d20ef06417c87a4c47ca44ed4f1f58c66df27201655a31fee3fc
|
|
BLAKE2b-256 checksum How to use checksums |
9208793d28cbaf6d5d33a02914a44086b8820325bc465dde95963d7314ede5c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pdschema 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.