# Introducing boolrule

boolrule is an open source Boolean expression evaluation engine for Python.

We originally built boolrule to evaluate conditional edges between nodes in a graph structure, which we then used to model a dynamic signup flow that changed automatically depending on the state of the pet or customer at a given point. The boolean expressions were essentially configuration data, and the use of a simple DSL means they could be read and edited by someone without a programming background.

We've actually found a multitude of other uses for it since, including using it in our promotion system to apply conditional discounts and in our order generation systems to conditionally include certain items in an order.

Probably the simplest (though not precicely useful) example of boolrule in action is evaluating a static expression:

>>> from boolrule import BoolRule
>>> rule = BoolRule('5 > 3')
>>> rule.test()
True


...but the real power comes when evaluating the boolean expression against a dynamically-generated context dict:

>>> can_buy_beer = BoolRule('user.age_years >= 18')
False
True


You can of course combine expressions using standard boolean operators like and, or and not along with parentheses:

>>> is_hipster = BoolRule('address.postcode.outcode in ("E1","E2") or user.has_beard = true')

If you're interested in finding out more, you can read the documentation, head over to the github repo or just pip install boolrule and start playing around.