Skip to main content

Lightweight Schema Validator

Project description

schemaguard

Lightweight 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.2.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.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: schemaguard-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 edfa8ba709ea181d9647d7f0320000e781671958bbf97b63c9ba47b6ac64e8a9
MD5 b3ec74534a6cf69d000bc3e2e070345f
BLAKE2b-256 eac38fe127b1fc73ebc3c171b542fa127da505ddf3a3e14ee07d1d6d34aa5e07

See more details on using hashes here.

File details

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

File metadata

  • Download URL: schemaguard-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87756596bcc8edc22a7ac29c44686951f0bff1d3a42ec61216a5019b1dd75134
MD5 a650cee7c957f48d69c53288d24027b2
BLAKE2b-256 a30a680bb0b441ccf4d951784c7ba539ef339b182300af118d433545e9e97f73

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