Skip to content
Simple boolean expression evaluation engine for python
Python Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
boolrule
docs Document new comparison and set membership operators (#11) Oct 19, 2019
tests Allow use of maths symbols for operators (#8) Oct 18, 2019
.editorconfig Set up project skeleton Sep 30, 2016
.gitignore
.travis.yml
AUTHORS.rst
CONTRIBUTING.rst
HISTORY.rst
LICENSE
MANIFEST.in
Makefile Set up project skeleton Sep 30, 2016
README.rst Switch pyup badge in readme for dependabot Oct 21, 2019
requirements_dev.txt
setup.cfg
setup.py
tox.ini

README.rst

boolrule

Documentation Status Dependencies

Simple boolean expression evaluation engine.

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.

You can’t perform that action at this time.