https://github.com/tailsdotcom/boolrule
Simple boolean expression evaluation engine for python.
https://github.com/tailsdotcom/boolrule
pyparsing python2 python3
Last synced: 12 months ago
JSON representation
Simple boolean expression evaluation engine for python.
- Host: GitHub
- URL: https://github.com/tailsdotcom/boolrule
- Owner: tailsdotcom
- License: mit
- Created: 2016-09-30T15:25:15.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-05-11T13:19:54.000Z (almost 3 years ago)
- Last Synced: 2025-03-27T13:01:40.452Z (about 1 year ago)
- Topics: pyparsing, python2, python3
- Language: Python
- Homepage: https://pypi.org/project/boolrule/
- Size: 133 KB
- Stars: 17
- Watchers: 17
- Forks: 4
- Open Issues: 10
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Security: SECURITY.md
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
========
boolrule
========
.. image:: https://img.shields.io/pypi/v/boolrule.svg
:target: https://pypi.python.org/pypi/boolrule
.. image:: https://github.com/tailsdotcom/boolrule/actions/workflows/ci.yml/badge.svg
:target: https://github.com/tailsdotcom/boolrule/actions/workflows/ci.yml
.. image:: https://readthedocs.org/projects/boolrule/badge/?version=latest
:target: https://boolrule.readthedocs.io/en/latest/?badge=latest
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.
.. _pyparsing: http://pyparsing.wikispaces.com/
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage