Skip to main content

Lightweight DataFrame Schema Validator

Project description

schemaguard

Lightweight DataFrame Schema Validator for Python

PyPI License: MIT


About

schemaguard is a lightweight Python library that allows you to define and validate schemas for Pandas DataFrames. It helps ensure your data meets expected formats, types, and constraints before entering production pipelines, saving you time and reducing errors.

With schemaguard, you can:

  • Define column types, nullability, uniqueness, regex patterns, and numeric bounds.
  • Validate Pandas DataFrames against YAML or Python-based schemas.
  • Version your schemas to track changes over time.
  • Integrate easily into ETL pipelines, Airflow, or CI/CD workflows.

Features

  • Column type validation (int, float, str, etc.)
  • Null check (not_null)
  • Uniqueness check (unique)
  • Regex pattern matching (regex)
  • Numeric bounds (min_value, max_value)
  • Schema versioning
  • YAML-based schema loader
  • Lightweight and fast, ideal for small and large datasets.

Installation

You can install schemaguard via pip:

pip install schemaguard

Or install from source for development:

git clone https://github.com/inzamam1121/schemaguard.git
cd schemaguard
pip install -e .

Quick Start

1. Define a YAML schema

Create files/schema_v1.yml:

version: "1.0"

columns:
  order_id:
    type: int
    not_null: true
    unique: true

  amount:
    type: float
    not_null: true
    min: 0
    max: 10000

  email:
    type: string
    regex: "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"

2. Validate your DataFrame

import pandas as pd
from schemaguard.loader.yaml_loader import load_schema_from_yaml

# Load schema
schema = load_schema_from_yaml("files/schema_v1.yml")

# Load data
df = pd.read_csv("files/data.csv")

# Validate
report = schema.validate(df, raise_on_error=False)

# Print report
print(report)

3. Sample Output

{
  'ok': False,
  'errors': {
    'amount': 'null values present',
    'email': 'regex mismatch',
    'order_id': 'duplicate values found'
  },
  'version': '1.0'
}

Versioning

schemaguard uses semantic versioning:

  • 0.1.0 — Initial release with YAML schema loader and basic validators.
  • Future releases will add more validators, performance improvements, and integration examples.

Use Cases

  • Validate incoming ETL data before storing in warehouse.
  • Ensure API payloads match expected schema.
  • Quickly enforce data contracts in collaborative teams.
  • Detect and prevent data quality issues in production.

Author

Inzamam Yousaf Email: uniprecisionofficial@gmail.com GitHub: https://github.com/inzamam1121


License

This project is licensed under the MIT License — see the LICENSE file for details.


Contributing

Contributions, issues, and feature requests are welcome! Feel free to fork the repository and submit pull requests.

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

schemaguard-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

schemaguard-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file schemaguard-0.1.0.tar.gz.

File metadata

  • Download URL: schemaguard-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for schemaguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07f2d22c651d831e5ca3cb1a0a1df5da1d65a6fae0660b99c689c98de2d45373
MD5 a44dee8f55061a809ab8c90d0a26ff8a
BLAKE2b-256 2ab803cb6b3e68099baa5c5f4d9a20492623122372f1e1c2dd17d44d9d581c70

See more details on using hashes here.

File details

Details for the file schemaguard-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: schemaguard-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for schemaguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6879aef360422c2e876e5e287b298bea064f3c6f323043efca886cfcabc46d9
MD5 bd60792e4f06fe6e0b1eac025671c338
BLAKE2b-256 7eb4cc85923aedf6ea30db30f73afbb63c3a056406b60fd03872668fb5f5df9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page