A tiny, composable, extensible rule engine for Python (Specification + Transformer).
Project description
easy-rule-engine
A tiny, composable rule engine for Python.
- Specification: composable predicates (
&,|,~) - Transformer: immutable transformations (returns a new item)
- Rule:
condition + transform (+ stop_on_match) - RuleEngine: applies rules to items (
match_mode=all|first,keep_unmatched)
Install
uv add easy-rule-engine
Quick start
from easy_rule_engine import Rule, RuleEngine, attr_spec, attr_transform, dict_setter
users = [
{"name": "Tom", "age": 15, "status": "UNKNOWN"},
{"name": "Alice", "age": 20, "status": "OK"},
]
get_age = lambda u: u["age"]
get_status = lambda u: u["status"]
is_minor = attr_spec(get_age, lambda v: v < 18)
set_minor = attr_transform(
getter=get_status,
setter=dict_setter("status"),
value_func=lambda _old: "MINOR",
)
engine = RuleEngine(
rules=[Rule(condition=is_minor, transform=set_minor, name="minor")],
keep_unmatched=True,
)
print(engine.process(users))
Examples
Example scripts live in examples/.
Recommended (after syncing the project environment; see Development):
uv run python examples/dict_filter_and_transform.py
uv run python examples/dataclass_transform.py
uv run python examples/order_discounts_and_shipping.py
uv run python examples/risk_scoring_with_priorities.py
uv run python examples/two_phase_pipeline.py
Development
Create/update the project environment (recommended; installs the project editable by default):
uv sync
Run unit tests:
uv run python -m unittest -q
If you want to disable editable installs (not recommended for development):
uv sync --no-editable
If you prefer not to install, you can still run from source with:
PYTHONPATH=src uv run python -m unittest -q
PYTHONPATH=src uv run python examples/dict_filter_and_transform.py
Build distributions (sdist + wheel):
uv pip install -U build
uv run python -m build
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 easy_rule_engine-0.1.0.tar.gz.
File metadata
- Download URL: easy_rule_engine-0.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c04d6c9a19a67c1aca8f19106e3225646d3dcd8cfb0b5aa5564223668060a4b
|
|
| MD5 |
b0b03c92ab607342e555e536a3ec3910
|
|
| BLAKE2b-256 |
86f13c9c506efee671b732a0c8da8db74b89677d05a33300eb83c89069bd9aa1
|
File details
Details for the file easy_rule_engine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: easy_rule_engine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
334f6294ba3ce5e723dd1ebb5637ce0204852b2e963672d27673f7d48726bddb
|
|
| MD5 |
2609029e816a73945076a125970cabc1
|
|
| BLAKE2b-256 |
efaaaa6c6cef1c1a98312671af2de557daefffeb4814bf346d2cee7ed3f4a0a9
|