Skip to main content

MIT License Python 3.10+ CI codecov

FluxRules

FluxRules is a Python library for authoring rules and evaluating them against facts. It is loosely based on the concepts from Drools’ Phreak engine.

Use FluxRules to keep decision logic separate from application flow and evaluate rules consistently across facts.

Core Capabilities

  • Evaluate a ruleset against facts using the top-level Python API.
  • Run rule evaluation through FluxRules’ Phreak engine in stateless or streaming mode.
  • Validate rulesets before evaluation.
  • Retrieve evaluation explanations
  • Use optional HTTP endpoints for evaluation, validation, explanations, and health checks.

Requirements

  • Python 3.10+

Installation

For local development, clone the repository and install the project with uv:

git clone https://github.com/fluxrules/fluxrules.git
cd fluxrules
uv sync --extra dev

This creates the project environment and installs FluxRules with its development tools. To install the published package in a virtual environment managed by uv:

uv venv
uv pip install fluxrules

Install an optional extra in the checkout with uv sync, for example:

uv sync --extra api
uv sync --extra sql
uv sync --extra redis
uv sync --extra otel
uv sync --extra yaml
uv sync --extra cli
uv sync --extra docs
uv sync --extra all

For more details see the installation guide.

Your First Rule

from fluxrules import Rule, evaluate

rule = Rule(
    name="high_value_transaction",
    condition_dsl={"type": "condition", "field": "amount", "op": ">", "value": 5000},
    action="manual_review",
)

result = evaluate(rule, {"amount": 6000})

print(f"Fired rules: {result.fired_rules}")
print(f"Actions: {result.actions}")

Output:

Fired rules: [1]
Actions: ['manual_review']

Constructing a Rule does no I/O and evaluate() takes rules directly, so there is nothing to configure to get an answer. evaluate() also accepts a list of rules, or a named Ruleset.

Using the engine directly

from fluxrules import PhreakEngine, Rule

rule = Rule(
    name="high_value_transaction",
    domain="payments",
    condition_dsl={"type": "condition", "field": "amount", "op": ">", "value": 5000},
    action="manual_review",
    priority=100,
)

engine = PhreakEngine()
engine.load_rules([rule])

for fact in ({"amount": 6000}, {"amount": 10}):
    result = engine.evaluate(fact)
    print(fact, "->", result.fired_rules, result.actions)

To persist a rule, call rule.save(), or pass persist=True when constructing it. See the persistence guide.

API Server (Optional)

uv sync --extra api
uvicorn fluxrules.api.app:create_app --factory --reload

see API for more detail.

CLI (Optional)

uv sync --extra cli
fluxrules --help

Documentation

DOCS

Contributing

CONTRIBUTING & CODE OF CONDUCT

Security

SECURITY

License

LICENSE

Metadata

Release files for fluxrules 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fluxrules 0.1.1
File Size Uploaded
fluxrules-0.1.1.tar.gz 806.2 kB Details

Built distribution (wheel)

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

Total release size: 1.2 MB

Release files / fluxrules-0.1.1.tar.gz

Download URL fluxrules-0.1.1.tar.gz
Size 806.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c7e4e0f1e61d331de4deb4de479eab015eace68ac724140d95cd5066aeb70a64
BLAKE2b-256 checksum
How to use checksums
e378a49e4961ca68710f619a6d6dad43281995777edc23c1aa2c9bb924fc65dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / fluxrules-0.1.1-py3-none-any.whl

Download URL fluxrules-0.1.1-py3-none-any.whl
Size 382.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bd9f26f88549be2678df26a287b5b78b5d8a3fb4aa9edd41e0854058e0e4db4
BLAKE2b-256 checksum
How to use checksums
4c00cca7560886b90b0f6bebbd8048a491c08e84bc8e204cb80a03b91fb6d2f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

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