StatGuardian
Data quality validation. 13x faster than pandera.
Stop data quality issues from reaching production. StatGuardian validates data at runtime, instantly catching schema violations, type errors, and anomalies.
Real Use Cases
This library is used for:
- See examples below
- Check GitHub issues for real-world usage
Get Started
# Quick example - copy and run
# See full docs for detailed usage
30-Second Start
from statguardian import validate
# Define your schema
schema = {
"user_id": int,
"email": str,
"age": {"type": int, "min": 0, "max": 150},
}
# Validate data
result = validate(df, schema)
if not result.is_valid:
print(result.violations)
Why StatGuardian?
| Feature | StatGuardian | Pandera |
|---|---|---|
| Speed | 13x faster | Standard |
| Pandas | Yes | Yes |
| Polars | Yes | No |
| DuckDB | Yes | No |
| Learning Curve | Minimal | Steep |
Real-World Use Cases
E-commerce Order Validation
schema = {
"order_id": str,
"amount": {"type": float, "min": 0},
"status": {"enum": ["pending", "shipped", "delivered"]},
}
validate(orders_df, schema)
ML Feature Pipeline
schema = {
"feature_x": {"type": float, "not_null": True},
"feature_y": {"type": float, "mean": 0, "std": 1},
}
result = validate(features, schema)
Data Lake Monitoring
result = validate(incoming_data, schema)
if result.has_drift:
alert("Schema changed!")
Key Capabilities
- 13x speed advantage over pandera
- Type checking with detailed error messages
- Automatic drift detection
- Anomaly detection built-in
- Supports Pandas, Polars, DuckDB with identical code
- Zero configuration—just Python
Performance
StatGuardian processes 1M rows in 0.3s (vs pandera's 4.2s).
| Dataset | Rows | StatGuardian | Pandera | Speedup |
|---|---|---|---|---|
| Orders | 100K | 12ms | 180ms | 15x |
| Telemetry | 1M | 340ms | 4200ms | 12x |
| Credit Card | 50M | 15s | 210s | 14x |
Features
Core Validation
- Type validation (int, float, str, bool, datetime, etc.)
- Min/max constraints for numeric types
- Enum validation for categorical data
- Null/not-null constraints
- Pattern matching for strings (regex)
- Custom validation functions
- Composite constraints (multiple rules per field)
Data Quality Analysis
- Automatic drift detection (schema changes)
- Anomaly detection (outliers, unexpected values)
- Statistical profiling (mean, std, quartiles)
- Missing value reporting
- Duplicate detection
Framework Support
- Pandas DataFrames (primary target)
- Polars DataFrames (full compatibility)
- DuckDB relations (streaming support)
- NumPy arrays (optional)
- Unified API across all frameworks
Performance & Scale
- Rust core for 13x speedup
- Streaming validation (memory-efficient)
- Batch processing (optimal for large datasets)
- Zero-copy operations where possible
Requirements
- Python: 3.10+
- Core: Rust-powered validation engine (precompiled)
- Data Frameworks:
- pandas ≥1.3.0 (primary)
- polars ≥0.19.0 (optional)
- duckdb ≥0.8.0 (optional)
- Optional: numpy ≥1.20.0 (for array support)
- Precompiled: Wheels for macOS, Linux, Windows (all Python 3.10-3.13)
Examples
Basic Type Validation
from statguardian import validate
# Simple schema
schema = {
"user_id": int,
"email": str,
"created_at": "datetime",
}
result = validate(df, schema)
print(f"Valid: {result.is_valid}")
print(f"Violations: {result.violations}")
Constraint Validation
schema = {
"age": {"type": int, "min": 0, "max": 150},
"email": {"type": str, "pattern": r"^[\w\.-]+@[\w\.-]+\.\w+$"},
"status": {"enum": ["active", "inactive", "pending"]},
"balance": {"type": float, "min": 0},
}
result = validate(transactions, schema)
if not result.is_valid:
for violation in result.violations:
print(f"Row {violation['row']}: {violation['message']}")
Drift & Anomaly Detection
# Detect schema changes
result = validate(new_data, schema)
if result.has_drift:
print(f"New columns: {result.new_fields}")
print(f"Missing columns: {result.missing_fields}")
# Detect anomalies
if result.anomalies:
print(f"Outlier rows: {result.anomaly_rows}")
Multi-Framework Validation
import pandas as pd
import polars as pl
# Pandas
df_pd = pd.read_csv("data.csv")
result_pd = validate(df_pd, schema)
# Polars (identical code)
df_pl = pl.read_csv("data.csv")
result_pl = validate(df_pl, schema)
# Both return same validation results
API Reference
Core Functions
-
validate(data, schema) -> ValidationResult- Validates data against schema
- Returns detailed violations report
- Supports Pandas, Polars, DuckDB
-
ValidationResult.is_valid: Boolean flag.violations: List of violations.has_drift: Boolean (schema changed).anomalies: List of anomaly indices.statistics: Profiling stats (count, mean, std, etc.)
Schema Constraints
- Type:
"int","float","str","bool","datetime" - Numeric:
min,max,mean,std - Categorical:
enum(allowed values) - String:
pattern(regex) - Nullability:
not_null(True/False) - Custom:
custom_fn(value) -> bool
Installation
pip install statguardian
# or with uv
uv pip install statguardian
# Verify installation
statguardian --version
For development:
git clone https://github.com/Mullassery/StatGuardian
cd StatGuardian
pip install -e ".[dev]"
pytest
Documentation
License
MIT License - See LICENSE
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file statguardian-2.3.2.tar.gz.
File metadata
- Download URL: statguardian-2.3.2.tar.gz
- Upload date:
- Size: 117.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b051856f4ee846b0d78bba2de1593aff1738f31e4afc87bd15ecbb9591e8567b
|
|
| MD5 |
db700c62916f277acaf8865d0caf7a98
|
|
| BLAKE2b-256 |
f581e32d123405e3c4021690b48dab9a00f818db378f8c73e1ca9979712b2b1b
|
File details
Details for the file statguardian-2.3.2-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: statguardian-2.3.2-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 9.7 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92982ed3dd8fc5da9d71e7aadeb0fcc4af700ba8ca1c7f72859e926407bc7570
|
|
| MD5 |
f8e81dca2dc3296acd0fa52471b6a8bc
|
|
| BLAKE2b-256 |
a0fa9c7f1d0b74ae4dd776cb256c5b03367364b62bd15f22ac6dc5265a06a769
|