Py-expression-eval is a lightweight Python library designed for evaluating mathematical and logical expressions from strings. It supports variables, custom functions, and a wide range of operators, making it suitable for dynamic calculation needs. The current version is 0.3.14. Releases are typically infrequent, focused on bug fixes and minor feature enhancements.
pip install py-expression-evalVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the parser, evaluate expressions with variables, use built-in functions, and leverage conditional operators. The `parse()` method returns an expression object which then can be evaluated with an optional dictionary of variables.
Test your existing expressions thoroughly after upgrading to 0.3.14. If issues arise, consider custom operator overriding or adjusting expressions.
Upgrade to version 0.3.10 or newer to use these operators. Alternatively, implement custom functions or operators for older versions.
Ensure you are on version 0.3.7 or newer for reliable `**` operator behavior. In older versions, use `pow(base, exponent)` if available, or stick to `^` (if defined differently in that version).
Upgrade to version 0.3.11 or newer for flexible string literal quoting. In older versions, ensure consistency with the default quote type (typically single quotes).
Add `from py_expression_eval import Parser` at the top of your Python file.
Upgrade your `py-expression-eval` library to version 0.3.10 or newer by running `pip install --upgrade py-expression-eval`.
Review your expression string for typos, correct syntax, and ensure all operators and functions are valid for your `py-expression-eval` version. Use single quotes for string literals if you are on an older version (<0.3.11).
Ensure you first parse the expression: `parsed_expression = parser.parse(expression_string)` then call `parsed_expression.evaluate(variables)`.
No dependency data recorded yet.