Boolexp
Boolexp provides “safe” evaluation of boolean expressions for use cases where eval might be dangerous. Boolexp expressions are context-free and mimic Python sytax. Only basic math opearations and data structures are provided.
Instalation
To install Boolexp, change to the directory where setup.py is located and type:
python setup.py install
Requirements:
Python 2.7
pyparsing 1.5.0 or later
Expression Syntax Overview
Basic math operators *,/,+,- have highest priority
>>> from boolexp import Expression
>>> Expression("4 + 4 / 2").evaluate()
>>> 6
>>> Expression("( 4 + 4 ) / 2 ").evaluate()
>>> 4
Comparsion operators !=, ==, <, >, <=, >=, in are next in priority. All comparsion operators have return type of boolean, which can be used as input for boolean operators and, or, not with lowest priority.
>>> from boolexp import Expression
>>> Expression(2 == 1).evaluate()
>>> False
>>> Expression("2 * - 2 == - 4").evaluate()
>>> True
>>> Expression("not 2 == 3").evaluate()
>>> True
>>> Expression("3 <= 8 and 2 == 5").evaluate()
>>> False
Expresions with with variables
This all would not be much of a fun without posibility to use variables. Allowed types for variables are bool,int,float,str,list,dict
>>> from boolexp import Expression
>>> Expression("1 in v").evaluate(dict(v=[1,2])).evaluate()
>>> True
>>> Expression("one[1].part == 2").evaluate(dict(one=[1, dict(part=2)], two=1)).evaluate()
>>> True
Diclaimer
This project is now in a state of proof of concept only, thus far from suitable for production enviroment.
Metadata
Release files for boolexp 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| boolexp-0.1.tar.gz | 3.1 kB | Without provenance | Details for boolexp-0.1.tar.gz |
Release files / boolexp-0.1.tar.gz
| Download URL | boolexp-0.1.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5e9e0e057143d3d0e54c00be7ec243216ea4aae8b705699be44dda58cff2f07
|
|
BLAKE2b-256 checksum How to use checksums |
0862d2c0215982fe03ee35d0277e35af47c5f8aae1559038039a372c8f822eb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for boolexp 0.1
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.