rule-engine Expression Language

4.5.3 · active · verified Wed Apr 15

rule-engine is a lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects. It provides a simple way to define and evaluate complex rules against data, supporting various data types and custom functions. The current stable version is 4.5.3, with frequent patch releases and a v5 alpha in active development.

Warnings

Install

Imports

Quickstart

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"]})})")

view raw JSON →