rule-engine
A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
What it is and what it does
Rule Engine is a domain-specific language (DSL) for writing matching rules as strings in Python code. You define rules using a custom grammar similar to Python syntax, then apply them to dictionaries or objects to test whether they match. The language supports optional type annotations to catch errors early, regular expression matching on strings, datetime values, and compound types like lists, dicts, and sets.
Typical usage involves creating a Rule object with an expression string, optionally providing a typed Context to validate symbol names and operations, then calling the rule's matching method on data objects. It's designed for scenarios where you need to express filtering or matching logic in a declarative, user-friendly way rather than writing Python conditionals directly. The package includes a debug REPL for experimentation.
Use it for:
- Filter records in a database or API response based on user-defined rule expressions without writing custom Python code
- Implement a rules engine for workflow automation where business logic is expressed as strings and evaluated at runtime
- Validate incoming data against typed rule sets to ensure only objects matching specific criteria proceed
- Build a query language for applications where end users need to define matching criteria without Python knowledge
- Match log entries or events against rule expressions for alerting or log aggregation systems
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Rule Engine provides a lightweight, custom expression language for evaluating rules against Python objects, with optional type hinting and support for regex matching, datetime handling, and compound data types.
Yes. Rule Engine is actively maintained, has no known vulnerabilities, low install friction, and solves a clear problem: declarative rule evaluation without writing Python code. The permissive BSD-3-Clause license poses no restrictions. Install if you need to evaluate user-defined or data-driven matching logic; skip if you're writing simple hardcoded conditionals.
Install
rule-engine on PyPI
pip
pip install rule-engineuv
uv add rule-enginepoetry
poetry add rule-engineInstalling rule-engine
Before you install
Low install friction with a single runtime dependency (python-dateutil). Active maintenance with a recent release 37 days ago and ongoing repository activity.
License in practice
BSD-3-Clause permissive license allows commercial and private use without restriction.
Quickstart
pip install rule-engine
import rule_engine
rule = rule_engine.Rule('first_name == "Luke" and email =~ ".*@rebels.org$"')
rule.matches({'first_name': 'Luke', 'email': 'luke@rebels.org'})
Requires Python 3.10 or later; Version 6.0 will drop Python 3.10 support.
Verify before relying
- Performance characteristics when evaluating large rule sets or complex expressions against many objects
- Thread-safety guarantees beyond the documented claim in the description excerpt
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — python-dateutil |
| Maintenance | actively maintained — 37 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 448,253/month — #6,604 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: rule_engine-5.0.2-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
PyMeta3PyMeta3 compiles pattern-matching grammars…
permissive · top 15,000 on PyPI
regressProvides Python bindings to the Rust regress…
permissive · top 5,000 on PyPI
common-expression-languageEvaluates Google's Common Expression Language…
permissive · top 15,000 on PyPI
ParsleyParsley is a PEG-based parsing library that…
permissive · top 5,000 on PyPI
zen-enginezen-engine is a Python binding for a Rust-based…
unclear · top 15,000 on PyPI
iregexp-checkValidates regular expressions against RFC 9485…
permissive · top 15,000 on PyPI
ctparseParses natural language time expressions (like…
permissive · top 15,000 on PyPI
exrexExrex generates all or random strings matching…
agpl · top 15,000 on PyPI
regexploitRegexploit analyzes regular expressions to…
permissive · top 15,000 on PyPI
yara-pythonyara-python provides a Python interface to…
permissive · top 5,000 on PyPI