Skip to content

Instantly share code, notes, and snippets.

@JohnAtl
Created October 26, 2022 02:41
Show Gist options
  • Save JohnAtl/7c6889bd70331f98977b57422d415f86 to your computer and use it in GitHub Desktop.
Save JohnAtl/7c6889bd70331f98977b57422d415f86 to your computer and use it in GitHub Desktop.
business_rule_engine demo
params = {
'products_in_stock': 10
}
def order_more(items_to_order):
print('you ordered {} new items'.format(items_to_order))
return items_to_order
with open('test.rules', 'r') as f:
rules = f.read()
from business_rule_engine import RuleParser
parser = RuleParser()
parser.register_function(order_more)
parser.parsestr(rules)
parser.execute(params)
rule "order new items"
when
products_in_stock < 20
then
order_more(50)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment