Skip to main content

Simple boolean expression evaluation engine

Project description

boolrule

https://img.shields.io/pypi/v/boolrule.svg https://github.com/tailsdotcom/boolrule/actions/workflows/ci.yml/badge.svg https://readthedocs.org/projects/boolrule/badge/?version=latest

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.

History

0.3.5 (2024-02-09)

  • Introduce not∩ operator

0.3.4 (2021-09-24)

  • Fixed error caused by early return when evaluating nested expressions.

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.

Source Distribution

boolrule-0.3.5.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boolrule-0.3.5-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file boolrule-0.3.5.tar.gz.

File metadata

  • Download URL: boolrule-0.3.5.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for boolrule-0.3.5.tar.gz
Algorithm Hash digest
SHA256 cea74e3fc9a605acae5e596214d877a689a27b06adf0ddc3bca3117d48121191
MD5 d3eb6450707a6b98a989fddf878d12a2
BLAKE2b-256 ef117875300b704b4a17d9c7e20e8597a325eb61e79f174d8a4609f2b0ba516d

See more details on using hashes here.

File details

Details for the file boolrule-0.3.5-py2.py3-none-any.whl.

File metadata

  • Download URL: boolrule-0.3.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for boolrule-0.3.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a3d654e28c8637ca4168777f193b11dd08dd73c24b233e5f1e3d727546cb01a7
MD5 dfb5a0818aa67f664445e1b71c461124
BLAKE2b-256 7ba779e6a38d19a69d4b621aa641e283cacc37ee4516a3a66e80ae91beb1c157

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page