asteval provides a safe, minimalistic, and flexible Python expression evaluator built on the Abstract Syntax Tree (AST) module. It is designed to evaluate untrusted code within a sandboxed environment, offering fine-grained control over available symbols and operations. The current version is 1.0.8, with a development cadence focused on security enhancements, bug fixes, and supporting newer Python versions.
pip install astevalVerified import paths — ran on the pinned version, not inferred.
Initialize an `Interpreter` instance, then use its callable interface or `eval()` method to execute Python expressions. Variables defined persist within the interpreter's symbol table, which can be accessed via `aeval.symtable`.
Review your code for usage of these functions. If absolutely necessary, re-enable them by adding them to the `Interpreter`'s symbol table with extreme caution, and fully understand the security implications of doing so.
Update `asteval` to version 1.0.8 or later to utilize `lambda` expressions. For older versions, refactor `lambda` functions into standard named `def` functions if possible.
Update `asteval` to version 1.0.7 or later to ensure correct and predictable `return` behavior within loops and blocks inside `asteval` functions.
Ensure your development and deployment environments use Python 3.10 or newer when working with recent versions of `asteval`.
Upgrade Python to version 3.8 or higher, or use a compatible version of asteval with your current Python version.
Ensure that both lmfit and asteval are updated to compatible versions that include the 'get_ast_names' function.
Upgrade to a newer version of lmfit that supports Python 2.7, or preferably, upgrade to Python 3.x and use the latest versions of both lmfit and asteval.
Install the 'six' module using 'pip install six' before installing asteval.
Initialize the variable or add the function to the `asteval` interpreter's symbol table (symtable) before evaluation.