Skip to main content

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.

Metadata

Release files for boolrule 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for boolrule 0.3.5
File Size Uploaded Provenance Actions
boolrule-0.3.5.tar.gz 17.9 kB Without provenance Details for boolrule-0.3.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for boolrule 0.3.5
File Interpreter ABI Platform Actions
boolrule-0.3.5-py2.py3-none-any.whl Python 2, Python 3 none any Details for boolrule-0.3.5-py2.py3-none-any.whl

Total release size: 24.4 kB

Release files / boolrule-0.3.5.tar.gz

Download URL boolrule-0.3.5.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cea74e3fc9a605acae5e596214d877a689a27b06adf0ddc3bca3117d48121191
BLAKE2b-256 checksum
How to use checksums
ef117875300b704b4a17d9c7e20e8597a325eb61e79f174d8a4609f2b0ba516d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / boolrule-0.3.5-py2.py3-none-any.whl

Download URL boolrule-0.3.5-py2.py3-none-any.whl
Size 6.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a3d654e28c8637ca4168777f193b11dd08dd73c24b233e5f1e3d727546cb01a7
BLAKE2b-256 checksum
How to use checksums
7ba779e6a38d19a69d4b621aa641e283cacc37ee4516a3a66e80ae91beb1c157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for boolrule 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page