Skip to content

santalvarez/python-rule-engine

Repository files navigation

python-rule-engine

pypi versions license

A rule engine where rules are defined in JSON format. The syntax of the rules belongs to the json-rules-engine javascript library though it contains some changes to make it more powerfull.

Installation

pip install python-rule-engine

Quick Example

from python_rule_engine import RuleEngine

rule = {
    "name": "basic_rule",
    "conditions": {
        "all": [
            {
                # JSONPath support
                "path": "$.person.name",
                "operator": "equal",
                "value": "Lionel"
            },
            {
                "path": "$.person.last_name",
                "operator": "equal",
                "value": "Messi"
            }
        ]
    }
}

obj = {
    "person": {
        "name": "Lionel",
        "last_name": "Messi"
    }
}

engine = RuleEngine([rule])

results = engine.evaluate(obj)

Rule Format

Find more info about the rules here.