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.
pip install python-rule-engine
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)
Find more info about the rules here.