Declarative DataFrame validation with rule bundles and JsonLogic
Project description
RuleFrame
RuleFrame validates pandas DataFrames with readable YAML or JSON rule bundles.
RuleFrame is useful when validation rules need to live outside application code: in files, database records, admin screens, or workflow configuration. A rule bundle describes the conditions that should produce findings, and RuleFrame returns both row-level findings and an annotated DataFrame.
Status
RuleFrame is in alpha. The core validation API is usable, but public APIs and rule syntax may
change before a stable 1.0.0 release.
Install
pip install ruleframe
Quick Start
import pandas as pd
from ruleframe import RuleBundle, validate_dataframe
rules_yaml = """
version: 1
rules:
- id: active_customer_missing_name
severity: error
fail_when:
all:
- column: Status
equals: "Active"
- column: Customer Name
is_blank: true
message: Active customers must have a name.
"""
df = pd.DataFrame(
{
"Status": ["Active", "Closed", "Active"],
"Customer Name": ["", "Grace Hopper", "Ada Lovelace"],
}
)
bundle = RuleBundle.from_yaml_string(rules_yaml)
result = validate_dataframe(df, bundle)
print(f"{len(result.findings)} finding(s)")
for finding in result.findings:
print(f"- row {finding.row_index}: [{finding.severity}] {finding.rule_id}")
print(f" {finding.message}")
annotated = result.to_annotated_dataframe()
print("\nRows:")
for row_index, row in annotated.iterrows():
name = row["Customer Name"] or "(missing)"
message = row["Validation Errors"] or "OK"
print(f"- row {row_index}: {row['Status']}, {name} -> {message}")
Expected output:
1 finding(s)
- row 0: [error] active_customer_missing_name
Active customers must have a name.
Rows:
- row 0: Active, (missing) -> Active customers must have a name.
- row 1: Closed, Grace Hopper -> OK
- row 2: Active, Ada Lovelace -> OK
validate_dataframe() returns a ValidationResult with:
to_findings_dataframe(): one row per rule finding.to_annotated_dataframe(): the original DataFrame plus computed columns and a validation message column.to_summary_dataframe(): finding counts grouped by rule and severity.
Rule Bundles
Rule bundles can be loaded from YAML, JSON, strings, or pre-parsed dictionaries:
from ruleframe import RuleBundle
bundle = RuleBundle.from_yaml("rules.yaml")
bundle = RuleBundle.from_json("rules.json")
bundle = RuleBundle.from_yaml_string(yaml_text)
bundle = RuleBundle.from_json_string(json_text)
bundle = RuleBundle.from_json_dict(data)
Rules support boolean nesting, literal comparisons, column-to-column comparisons, date comparisons, blank checks, membership checks, string containment, ranges, and generated computed columns.
Documentation
Project details
Release history Release notifications | RSS feed
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 ruleframe-0.1.0.tar.gz.
File metadata
- Download URL: ruleframe-0.1.0.tar.gz
- Upload date:
- Size: 37.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8831d9c030f80debb3085fed50727d7840e74c87ba649e9770706166cfeda35d
|
|
| MD5 |
5bb166ed2e6c0269b3b333380ec96e2c
|
|
| BLAKE2b-256 |
625d3168d165cf6eefba957acb6a90abbc14d195aa577ec5af141d8acb80f280
|
Provenance
The following attestation bundles were made for ruleframe-0.1.0.tar.gz:
Publisher:
publish.yml on RI-Advisory-Services/ruleframe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ruleframe-0.1.0.tar.gz -
Subject digest:
8831d9c030f80debb3085fed50727d7840e74c87ba649e9770706166cfeda35d - Sigstore transparency entry: 1795914447
- Sigstore integration time:
-
Permalink:
RI-Advisory-Services/ruleframe@b9543ba965ca28e2726dc79eb2177ed09d9e2c60 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/RI-Advisory-Services
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b9543ba965ca28e2726dc79eb2177ed09d9e2c60 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ruleframe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ruleframe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ad11bd30e80b70e3456e69b6bcf5d89e403ef73633c09719c3591bec67ba6bc
|
|
| MD5 |
923e850e4782e18f9b9dd05df61575ea
|
|
| BLAKE2b-256 |
f5a9433509f6d53b67aa5f0983d90dd55857f8a2cec34c1aaa7c29f5b8f2ed2a
|
Provenance
The following attestation bundles were made for ruleframe-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on RI-Advisory-Services/ruleframe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ruleframe-0.1.0-py3-none-any.whl -
Subject digest:
7ad11bd30e80b70e3456e69b6bcf5d89e403ef73633c09719c3591bec67ba6bc - Sigstore transparency entry: 1795915043
- Sigstore integration time:
-
Permalink:
RI-Advisory-Services/ruleframe@b9543ba965ca28e2726dc79eb2177ed09d9e2c60 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/RI-Advisory-Services
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b9543ba965ca28e2726dc79eb2177ed09d9e2c60 -
Trigger Event:
release
-
Statement type: