Skip to content

tailsdotcom/boolrule

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

boolrule

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.

About

Simple boolean expression evaluation engine for python.

Topics

Resources

License

Stars

Watchers

Forks