safe embedded python expression parser
Project description
safe embedded python expression parser (for mainly easy DSL or config file).
Getting Started
pip install embexpr
How to Use
from embexpr import Expr, ParseError
assert Expr('3 * 5')() == 15
assert Expr('"foo" + "bar"')() == "foobar"
assert Expr('len("example")')() == 7
assert Expr('s.startswith("prefix_")')(s="prefix_suffix") == True
try:
Expr('eval("1")')()
except ParseError as e:
print(e)
Reference
https://github.com/ansible/ansible/blob/devel/lib/ansible/template/safe_eval.py http://stackoverflow.com/questions/12523516/using-ast-and-whitelists-to-make-pythons-eval-safe
License
MIT
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
embexpr-1.1.0.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for embexpr-1.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78e551b76110825c98bf6aed1bfbd812267a175820a3cd3ea5eb73deb7e2a5e1 |
|
MD5 | 58785f4942d45abd38d9954284259284 |
|
BLAKE2b-256 | c136596fc30c9a416b9fdeb150a96aba1893f366ed5b59a59d4c2a756081884d |