Skip to main content

WinstonRedGuard local-first deterministic rule evaluation engine

Project description

rule-lab

A lightweight, local-first, deterministic rule evaluation engine for Python.

Define rules in JSON, evaluate them against any context, detect conflicts, and simulate outcomes — with zero external dependencies.

PyPI version Python 3.10+ License: MIT

Installation

pip install rule-lab

Quick Start

from rule_lab import load_rules_from_dict, evaluate_rules

ruleset = {
    "rules": [
        {
            "rule_id": "r1",
            "name": "Block high risk",
            "conditions": [{"field": "risk_score", "op": "gt", "value": 80}],
            "action": "block",
            "priority": 10
        }
    ]
}

rules = load_rules_from_dict(ruleset)
result = evaluate_rules(rules, context={"risk_score": 95})

print(result.matched_count)    # 1
print(result.results[0].action)  # block

CLI

# Validate a rule file
rule-lab validate --rules rules.json

# Simulate rules against a list of contexts
rule-lab simulate --rules rules.json --contexts contexts.json

# Detect conflicting rules
rule-lab diff --rules rules.json

API Reference

Function Description
load_rules_from_file(path) Load rules from a JSON file
load_rules_from_dict(data) Load rules from a dict
load_rules_from_list(rules) Load rules from a list
evaluate_rule(rule, context) Evaluate a single rule
evaluate_rules(rules, context) Evaluate a list of rules
simulate(rules, contexts) Simulate multiple contexts

Rule Format

{
  "rules": [
    {
      "rule_id": "unique-id",
      "name": "Human readable name",
      "conditions": [
        {"field": "score", "op": "gt", "value": 50}
      ],
      "action": "approve",
      "priority": 10,
      "tags": ["finance", "v1"],
      "metadata": {}
    }
  ]
}

Use Cases

  • AI release gating — validate LLM app outputs before production
  • Policy enforcement — define and run compliance rules as code
  • Decision engines — replace hardcoded if/else logic with JSON rules
  • Audit trails — every rule evaluation is traceable and reproducible

Design Principles

  • Zero dependencies — stdlib only, no surprise installs
  • Deterministic — same input always produces same output
  • Local-first — no network calls, no cloud required
  • Testable — every rule is independently verifiable

License

MIT — built by WinstonRed

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

rule_lab-0.1.2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rule_lab-0.1.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file rule_lab-0.1.2.tar.gz.

File metadata

  • Download URL: rule_lab-0.1.2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for rule_lab-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b3ebfd8e9ab62721309b1b2f82ba1f7019eead9e8f256f0775435da6500216ea
MD5 b0511860550a5d141ca787e8c845a22a
BLAKE2b-256 e6c8c30218e92d67f52e538c955de3143ac4cb0332a0c2af545e93c422ac2f82

See more details on using hashes here.

File details

Details for the file rule_lab-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: rule_lab-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for rule_lab-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29567b44c3946c6b02ebb0a25829a4ea9c8c68ee25caa3799a16048ce9debfeb
MD5 3a2a9a3b5e56ed6c7c638a7493ac75fd
BLAKE2b-256 b0170f90cb7bf59c74d2cfd289a15dd2fde2f5d11fbe3c1eff99675b9cb8a6f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page