formparse¶
Simple library for evaluating mathematical formulas.
Written as an safe alternative to Pythons eval() function the aim was to provide a lightweight library that could
evaluate mathematical formulas provided by users in a safe way.
Installation¶
You can install this package unsing pip:
pip install formparse
SECURITY WARNING!¶
Note
This package is currently pre-stable and some security features are still missing.
Usage¶
from formparse import Formula
formula = Formula('3*x**2')
result = formula.eval({'x': 2})
Alternatives¶
numexpr:¶
numexpr is a Python library for numpy that accelerates array operations
but it can hadnle simple string calculations as well. It is therefore a lot bigger than
formparse but if you are using numpy anyways in you project or need additional
features that we do not provide this might be a good fit. Check out its repo
here .