As a software system grows in complexity and usage, it can become burdensome if every change to the logic/behavior of the system also requires you to write and deploy new code. The goal of this business rules engine is to provide a simple interface allowing anyone to capture new rules and logic defining the behavior of a system, and a way to then process those rules on the backend.
You might, for example, find this is a useful way for analysts to define marketing logic around when certain customers or items are eligible for a discount or to automate emails after users enter a certain state or go through a particular sequence of events.
Variables represent values in your system, usually the value of some particular object. You create rules by setting threshold conditions such that when a variable is computed that triggers the condition some action is taken.
params = {
'products_in_stock': 10
}
def order_more(items_to_order):
print("you ordered {} new items".format(items_to_order))
return items_to_order
rules = """
rule "order new items"
when
products_in_stock < 20
then
order_more(50)
end
"""
from business_rule_engine import RuleParser
parser = RuleParser()
parser.register_function(order_more)
parser.parsestr(rules)
parser.execute(params)
Business rule engine uses Excel like functions. So it is possible to use most of them in the rules.