Skip to main content

WinstonRedGuard local-first deterministic rule evaluation engine (formerly rule-lab on PyPI, republished under WRG namespace)

Project description

wrg-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.11+ CI CodeQL License: MIT

Note: Previously published as rule-lab on PyPI. Access to that account was lost; releases continue here as wrg-rule-lab under the WRG namespace. The import path rule_lab is unchanged.

Installation

pip install wrg-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 WinstonRedGuard

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

wrg_rule_lab-0.1.5.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

wrg_rule_lab-0.1.5-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file wrg_rule_lab-0.1.5.tar.gz.

File metadata

  • Download URL: wrg_rule_lab-0.1.5.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for wrg_rule_lab-0.1.5.tar.gz
Algorithm Hash digest
SHA256 7963c26f62738c580d933ca95dc1d8f98bd4b3539dab2823976c3c3d2415d3a3
MD5 a8b2de2d5215911789e9dd3618f8b706
BLAKE2b-256 0d1982b5017fcc20388d97a5b29f83b943b93b8024190dfcf93af5bc2594f636

See more details on using hashes here.

Provenance

The following attestation bundles were made for wrg_rule_lab-0.1.5.tar.gz:

Publisher: publish.yml on WRG-11/wrg-rule-lab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wrg_rule_lab-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: wrg_rule_lab-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for wrg_rule_lab-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2ea1f1014506b59d959cbcadbaa5c79a54df3ae98fe35eb7affbf7738091fe19
MD5 60bf6726b2d0840549fb5df467bbbec8
BLAKE2b-256 caba5397d3408707784ab1ded4231b4eb7d8e3814850c7853ab0b3841c2feeb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for wrg_rule_lab-0.1.5-py3-none-any.whl:

Publisher: publish.yml on WRG-11/wrg-rule-lab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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