Install & Compatibility
Where this runs
tested against v5.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.641s · 19.6MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.8s · import 0.590s · 20MB
18MB installed
● package 18MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Rule
✓ from rule_engine import Rule
Context
✓ from rule_engine import Context
Used for advanced scenarios like custom functions or type definitions.
DataType
✓ from rule_engine import DataType
Essential when defining custom data types or explicit type coercions.
This quickstart demonstrates how to create a `Rule` instance with an expression string and then evaluate it against a Python dictionary acting as the data context. The rule expression uses built-in functions like `sum` and logical operators.
from rule_engine import Rule
# Define a rule with an expression string
rule = Rule('sum(items) > 100 && "apple" in items')
# Evaluate the rule against different data contexts
print(f"Result 1: {rule.matches({'items': [10, 20, 30, 40, 50, "apple"]})})")
print(f"Result 2: {rule.matches({'items': [10, 20, "orange"]})})")
Debug
Known issues
breakingVersion 5.0.0 is in alpha (v5.0.0a1 has been released) and introduces significant breaking changes and API refactors. Do not update to v5.x without thoroughly reviewing the changelog and migrating your code.fixPin your dependency to `rule-engine<5.0.0` to avoid accidental upgrades. Consult the v5 changelog when you're ready to migrate.
affects: All versions prior to 5.0.0
gotchaFrom v4.5.0 onwards, rule-engine is stricter about invalid string literals and function return types. `StringSyntaxError` is now raised for malformed string literals and `FunctionCallError` for type-incompatible function returns, where previous versions might have had different behavior.fixEnsure string literals are correctly formatted and custom functions return values compatible with their declared `DataType`.
affects: >=4.5.0
gotchaThe backslash character (`\`) is used for escaping in rule strings. If you need a literal backslash in your rule (e.g., in a regex pattern or string literal), you must double-escape it (e.g., `\\`).fixEscape literal backslashes by doubling them: `"\\"` in the rule string to represent a single backslash.
affects: All versions
gotchaWhen defining custom functions or interacting with complex Python objects, ensure you correctly use `Context` and `DataType` objects. Incorrect type declarations or context setup can lead to unexpected `FunctionCallError` or evaluation issues.fixRefer to the official documentation on `Context` and `DataType` for defining custom functions and managing evaluation environments effectively.
affects: All versions
Upgrade
Version history
5.0.0latest on PyPI · released May 17, 2026
Audit
Dependencies
No dependency data recorded yet.
Resources
No resource links recorded.