--- id: asteval version: "1.0.9" license: MIT license_treatment: permissive maintenance: active --- # asteval — Safe, minimalistic evaluator of python expression using ast module License: permissive · Maintenance: active · Downloads: 6.3M/mo ## What it is and what it does Asteval is a restricted Python interpreter that safely evaluates expressions and statements by parsing them into Python's abstract syntax tree (AST) and walking the tree to compute results. It supports a large subset of Python—conditionals, loops, comprehensions, f-strings, standard data structures, and math/NumPy functions when available—while intentionally blocking unsafe operations like class creation, module imports, eval/exec, and access to private methods. This makes it suitable for embedding in applications that need to accept user-written formulas or scripts without the security risks of Python's eval(). The package has no external runtime dependencies and works with Python 3.10 and later, including PyPy. It emphasizes mathematical expressions, so NumPy functions are automatically available if NumPy is installed. Programmers can inject custom functions and data into each Asteval session, and users can define their own functions within the language's constraints. The AST-based approach guarantees parsing identical to Python's, making correctness straightforward to verify. Use it for: - Embed a formula or macro language in a GUI or web application to let users define calculations without exposing eval() risks. - Build a simple calculator or expression evaluator for mathematical or scientific workflows. - Parse and execute user-supplied configuration or rule definitions in a controlled sandbox. - Evaluate conditional expressions or transformations in data processing pipelines. - Prototype or test Python logic without running untrusted code in the main interpreter. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Asteval is a safe Python expression and statement evaluator that uses the ast module to interpret user input without the risks of Python's built-in eval(). Yes. Asteval is a mature, actively maintained package (latest release 2026-06-11, no known vulnerabilities) with zero runtime dependencies and low install friction. It solves a real security problem—safe evaluation of user input—and is well-suited for embedded scripting, mathematical evaluation, or any scenario where you need Python-like syntax without the risks of eval(). The MIT license is permissive. Install it if you need to accept and execute user-written expressions safely. ## Install pip install asteval uv add asteval poetry add asteval ## Installing asteval Before you install: Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-08-11, supports Python 3.10 through 3.14 and PyPy. No known vulnerabilities. License in practice: MIT license permits commercial and private use with minimal restrictions—include a copy of the license and attribution when distributing. Quickstart: pip install asteval from asteval import Interpreter interp = Interpreter() result = interp('2 * x + 1', x=5) print(result) # 11 Requires Python 3.10 or higher. Verify before relying: - Whether NumPy integration is automatic or requires explicit configuration when NumPy is installed. - Performance characteristics when evaluating complex or deeply nested expressions. - Whether custom function registration persists across multiple eval() calls in the same Interpreter instance. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 6.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags safe python expression evaluator, restricted python interpreter, ast-based code evaluation, embedded scripting language, user input evaluation, mathematical expression parser, sandboxed python execution, sandboxed-execution, expression-evaluation, embedded-scripting [View on SkillFed](https://skillfed.io/packages/asteval) · [View on PyPI](https://pypi.org/project/asteval/)