Skip to main content

Simple boolean expression evaluation engine

Project description


Simple boolean expression evaluation engine.


Compare simple boolean statements:

>>> rule = BoolRule('5 > 3')
>>> rule.test()
>>> rule = BoolRule('5 < 3')
>>> rule.test()

Evaluate boolean statements against a context dict:

>>> can_buy_beer = BoolRule('user.age_years >= 18')
>>> can_buy_beer.test({'user':{'age_years': 12}})
>>> can_buy_beer.test({'user':{'age_years': 20}})

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})


Made possible by the excellent pyparsing library.

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.


0.3.3 (2021-07-15)

  • Upgrade dependencies.

0.3.2 (2020-09-23)

  • Add Type hinting.

0.3.1 (2020-09-09)

  • Raise an exception when the whole expression cannot be parsed. Previous behaviour would discard the segment that didn’t match the expression grammar.

0.3.0 (2018-01-15)

  • Add None type and is/isnot operators (contributed by ocurero)

0.2.0 (2016-10-27)

  • Fixed error caused by refactor from internal codebase that was preventing deep context level values from being referenced in a substitution value

0.1.2 (2016-09-30)

  • Improved documentation

0.1.1 (2016-09-30)

  • Made context optional
  • Improved documentation

0.1.0 (2016-09-30)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for boolrule, version 0.3.3
Filename, size File type Python version Upload date Hashes
Filename, size boolrule-0.3.3-py2.py3-none-any.whl (6.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size boolrule-0.3.3.tar.gz (17.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page