Skip to main content

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

Release files for ruleframe 0.1.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 ruleframe 0.1.0
File Size Uploaded
ruleframe-0.1.0.tar.gz 37.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ruleframe 0.1.0
File Interpreter ABI Platform
ruleframe-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 59.8 kB

Release files / ruleframe-0.1.0.tar.gz

Download URL ruleframe-0.1.0.tar.gz
Size 37.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8831d9c030f80debb3085fed50727d7840e74c87ba649e9770706166cfeda35d
BLAKE2b-256 checksum
How to use checksums
625d3168d165cf6eefba957acb6a90abbc14d195aa577ec5af141d8acb80f280
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.

Transparency log

Release files / ruleframe-0.1.0-py3-none-any.whl

Download URL ruleframe-0.1.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ad11bd30e80b70e3456e69b6bcf5d89e403ef73633c09719c3591bec67ba6bc
BLAKE2b-256 checksum
How to use checksums
f5a9433509f6d53b67aa5f0983d90dd55857f8a2cec34c1aaa7c29f5b8f2ed2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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