python-rule-engine

A rule engine where rules are written in JSON format


Keywords
rule-engine, rules, json, python, rules-engine
License
MIT
Install
pip install python-rule-engine==0.5.0

Documentation

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.