Lightweight data quality validation framework for big data pipelines
Project description
Why DataGuard?
Data quality issues cost organizations millions annually. Existing solutions like Great Expectations are powerful but heavy. DataGuard provides a lightweight, intuitive alternative that works seamlessly with both Pandas and PySpark — perfect for big data pipelines.
- ✅ Dual Engine: First-class support for both Pandas & PySpark
- ✅ Declarative Rules: Define validation rules cleanly, no boilerplate
- ✅ Threshold-based: Set pass-rate thresholds per rule (not just pass/fail)
- ✅ Data Profiling: Auto-generate column-level statistics
- ✅ Rich Reports: Human-readable summaries + JSON export for CI/CD
- ✅ Zero Config: Works out of the box, no setup files needed
Quick Start
Installation
# Basic (Pandas engine)
pip install dataguard
# With PySpark support
pip install dataguard[spark]
Basic Usage
import pandas as pd
from dataguard import DataGuard, RuleSet, not_null, in_range, in_set, regex_match
# Create a DataFrame
df = pd.DataFrame({
"name": ["Alice", "Bob", "Charlie", None, "Eve"],
"age": [25, 30, -1, 40, 150],
"email": ["alice@example.com", "invalid", "charlie@example.com", "dana@example.com", "eve@example.com"],
"status": ["active", "active", "inactive", "active", "unknown"],
})
# Define validation rules
rules = RuleSet()
rules.add("name", not_null())
rules.add("age", not_null())
rules.add("age", in_range(0, 120))
rules.add("email", regex_match(r"^[\w.-]+@[\w.-]+\.\w+$"))
rules.add("status", in_set(["active", "inactive"]))
# Run validation
guardian = DataGuard(df)
report = guardian.validate(rules)
# Print summary
print(report.summary())
Output:
DataGuard Validation Report
Engine: pandas
Total Rules: 5 | Passed: 1 | Failed: 4
Overall Status: INVALID
------------------------------------------------------------
[FAIL] name.not_null | pass_rate=80.00% (threshold=100%) | 4/5 rows passed
[PASS] age.not_null | pass_rate=100.00% (threshold=100%) | 5/5 rows passed
[FAIL] age.in_range(0, 120) | pass_rate=80.00% (threshold=100%) | 4/5 rows passed
[FAIL] email.regex_match(...) | pass_rate=80.00% (threshold=100%) | 4/5 rows passed
[FAIL] status.in_set(...) | pass_rate=80.00% (threshold=100%) | 4/5 rows passed
With PySpark
from pyspark.sql import SparkSession
from dataguard import DataGuard, RuleSet, not_null, in_range
spark = SparkSession.builder.appName("DataGuard").getOrCreate()
df = spark.read.parquet("s3://my-bucket/data/")
rules = RuleSet()
rules.add("user_id", not_null())
rules.add("user_id", unique())
rules.add("age", in_range(0, 120))
report = DataGuard(df).validate(rules)
Threshold-based Validation
Not every dataset needs 100% compliance. Set thresholds per rule:
rules = RuleSet()
# Allow up to 5% null values in optional fields
rules.add("middle_name", not_null(), threshold=0.95)
# Require 99.9% uniqueness for IDs
rules.add("transaction_id", unique(), threshold=0.999)
Data Profiling
guardian = DataGuard(df)
profile = guardian.profile()
for col, stats in profile.items():
print(f"{col}: {stats['distinct_count']} distinct, {stats['null_rate']:.2%} nulls")
JSON Export (for CI/CD integration)
report = guardian.validate(rules)
print(report.to_json())
Built-in Checks
| Check | Description |
|---|---|
not_null() |
Value must not be None/NaN |
unique() |
Column values must be unique |
in_range(min, max) |
Numeric value within range (inclusive) |
regex_match(pattern) |
String matches regex pattern |
in_set(values) |
Value in allowed set |
min_length(n) |
String has at least n characters |
max_length(n) |
String has at most n characters |
custom(fn, name) |
Custom validation function |
Architecture
dataguard/
├── __init__.py # Public API
├── core.py # DataGuard main class
├── rules.py # Rule & RuleSet definitions
├── checks.py # Built-in check functions
├── report.py # ValidationReport & ValidationResult
├── exceptions.py # Custom exceptions
├── pandas_engine.py # Pandas validation backend
└── spark_engine.py # PySpark validation backend
Roadmap
- Great Expectations interop layer
- dbt integration
- SQL-based validation engine
- Streaming data validation (Spark Structured Streaming)
- CLI tool for one-off validation jobs
- Visualization dashboard
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License — see the LICENSE file for details.
中文介绍
DataGuard 是一个轻量级的大数据管道数据质量验证框架,核心特性:
- 双引擎支持:原生支持 Pandas 和 PySpark,无需切换工具
- 声明式规则:用简洁的语法定义验证规则,告别样板代码
- 阈值验证:支持按规则设置通过率阈值,而非简单的二元判断
- 数据画像:一键生成列级统计信息
- 丰富报告:支持人类可读摘要 + JSON 导出,方便 CI/CD 集成
- 零配置:开箱即用,无需配置文件
适用于数据工程师在 ETL/ELT 管道中进行数据质量检查,也适用于数据科学家在分析前验证数据完整性。
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
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 dqguard-0.1.0.tar.gz.
File metadata
- Download URL: dqguard-0.1.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a8972634c0f5054b097a2bcc410d9743b2c97bd4e1a82d451a939dbc66eb4f6
|
|
| MD5 |
b0c614941aae71cff673bdd94bcc8b4c
|
|
| BLAKE2b-256 |
6e7da121719b3b69196cfd8da33199d7e47e9f30e528582bfead2665f49b5475
|
File details
Details for the file dqguard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dqguard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f05daf88f9f58b0d5d0105f9a72e48cc7a3acc4b13f6e6a77ace507a91fc6de
|
|
| MD5 |
94cf3f9c5266b117595ed8c754af4312
|
|
| BLAKE2b-256 |
9b11e0e1bfcba302038207fc0d9d1b1ba7d9a7175338cd9e78a1e2ffb7005296
|