boolrule¶
Simple boolean expression evaluation engine.
- Free software: MIT license
- Documentation: https://boolrule.readthedocs.io.
Features¶
Compare simple boolean statements:
>>> rule = BoolRule('5 > 3')
>>> rule.test()
True
>>> rule = BoolRule('5 < 3')
>>> rule.test()
False
Evaluate boolean statements against a context dict:
>>> can_buy_beer = BoolRule('user.age_years >= 18')
>>> can_buy_beer.test({'user':{'age_years': 12}})
False
>>> can_buy_beer.test({'user':{'age_years': 20}})
True
Combine conditions with and and or operators to produce complex expressions:
>>> is_hipster = BoolRule('address.postcode.outcode in ("E1","E2") or user.has_beard = true')
>>> address = {
>>> 'postcode': {
>>> 'outcode': 'E1'
>>> }
>>> }
>>> is_hipster.test({'has_beard': False, 'address': address})
True
Credits¶
Made possible by the excellent pyparsing library.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.