Skip to main content

StatGuardian

A Rust-native data quality engine with a declarative contract DSL for schema validation, drift detection, and anomaly detection for Pandas and Polars DataFrames.

What it is

StatGuardian validates data at runtime against versionable contracts written in a declarative .sg DSL. It catches schema violations, statistical drift, and anomalies before they reach downstream consumers. The core validation and statistics logic run in Rust while providing a Python API for integration into data pipelines.

Features / Highlights

  • Declarative contracts: Define schema, quality rules, statistical drift thresholds, and anomaly checks in one .sg file.
  • Rust-native execution: Core checks and statistics execute in compiled Rust for performance.
  • Multi-backend support: Validate Pandas and Polars DataFrames with the same contract. Delta Lake and Apache Iceberg tables are supported as inputs.
  • Drift detection: Detect distribution shifts between datasets using PSI and KS tests via the DSL.
  • Anomaly detection: Identify outliers and duplicates with built-in rules.
  • Blocking controls: Severity tiers let you mark critical checks as @blocking to gate pipeline execution.
  • Detailed reports: Structured violation messages, scores, and per-check results.

Who it's for / Use cases

  • Data engineering pipelines: Enforce contracts on batch or streaming inputs before writes.
  • MLOps/feature pipelines: Catch schema or distribution drift between training and inference data.
  • ETL/data integration: Validate external data against agreed schemas and quality thresholds.
  • Data governance: Version and review contracts alongside code as the source of truth.

What it is not

  • Not a full observability platform: Focused on contract-based validation; does not include dashboards/alerting infrastructure beyond returning structured reports.
  • Not a generic testing framework: Designed for data contract enforcement at runtime and in pipelines.
  • Benchmarks vary: Performance depends on workload (row count, columns, checks). Run benchmarks against your own data before making comparisons.

Project status

StatGuardian is in active development. Core features (schema validation, quality rules, drift, anomaly detection, multi-backend DataFrame support) are implemented. Streaming validation (StreamGuard) and additional integrations are documented under development paths; see docs/ROADMAP_HONEST.md for known limitations and planned work.

Installation

From PyPI

pip install statguardian

From source (Python + Rust)

pip install maturin
maturin develop

System requirements

  • Python 3.8+
  • Rust toolchain (for source builds)

Quick start

import polars as pl
import statguardian

contract = statguardian.DataContract.from_dsl("""
dataset orders {
    schema {
        order_id: string, not_null, unique
        amount:   float,  positive
        status:   string, not_null, enum=["pending","paid","cancelled"]
    }
    quality {
        completeness(order_id) > 0.999
    }
}
""")

df = pl.read_parquet("orders.parquet")
report = statguardian.execute(contract, df)
print(report.summary())
print(f"Passed: {report.passed}")

Usage

Validate a Polars DataFrame against a contract:

import statguardian

contract = statguardian.DataContract.from_dsl("dataset orders { schema { id: string, not_null } }")
report = statguardian.execute(contract, df)

Drift detection between reference and incoming data:

report = statguardian.execute(contract, incoming_df, reference=baseline_df)
for d in report.drift_results():
    if not d["passed"]:
        print(f"Drift: {d['column']} PSI={d.get('psi', 0):.4f}")

Load a contract from a .sg file:

contract = statguardian.DataContract.from_file("contracts/orders.sg")

Note: When validating a Pandas DataFrame, convert it to Polars first (e.g., pl.from_pandas(df)) before calling execute().

Documentation

Contributing

Contributions are welcome. Please review CONTRIBUTING.md for guidelines on development setup, code style, and testing.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Metadata

Release files for statguardian 2.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for statguardian 2.7.0
File Size Uploaded
statguardian-2.7.0.tar.gz 150.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for statguardian 2.7.0
File Interpreter ABI Platform
statguardian-2.7.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details

Total release size: 17.1 MB

Release files / statguardian-2.7.0.tar.gz

Download URL statguardian-2.7.0.tar.gz
Size 150.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1c886d1b86c7a61f74a02144799197d329f14ef9cbadf53dd1b5af85fb8e0f6a
BLAKE2b-256 checksum
How to use checksums
6df5ea9e215ced68ecee2f8eedadbe618a3e94307128bf76c5ff99417dadc6b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / statguardian-2.7.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL statguardian-2.7.0-cp38-abi3-macosx_11_0_arm64.whl
Size 16.9 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f9b782133cd5b7ffb3827de91f21976a6499df98ae470e8ec6f4ef7f6be0d4c4
BLAKE2b-256 checksum
How to use checksums
675e98393f376892e0505301813b4c1eee38c5bade6f58c3446b1ab6e41c117d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

2.7.0 This release

2 release files

2.6.3

2 release files

2.6.2

2 release files

2.6.1

1 release file

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.2

2 release files

2.3.1

1 release file

2.3.0

2 release files

2.2.1

1 release file

2.2.0

1 release file

2.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page