asteval
Safe, minimalistic evaluator of python expression using ast module
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or higher.
- 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.
License · maintenance · safety
MIT (permissive) — MIT license permits commercial and private use with minimal restrictions—include a copy of the license and attribution when distributing.
last release 2026-06-11 (64 days) · last repo commit 2026-08-11 · 220 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 6,261,626 downloads/mo, #1,945 on PyPI
Alternatives
Verify before relying
pip install asteval
from asteval import Interpreter
interp = Interpreter()
result = interp('2 * x + 1', x=5)
print(result) # 11- 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.
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 on this page. Verify before relying on it.
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
asteval on PyPI
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.
Requires Python 3.10 or higher.
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
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 the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 64 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,261,626 / month, #1,945 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: PyPy |
Evidence: asteval-1.0.9-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “ast-based code evaluation”
- astevalAsteval is a safe Python expression and statement evaluator that uses…
- simpleevalEvaluates mathematical and logical expressions from strings in a…
- pure-evalSafely evaluate Python AST nodes without executing arbitrary code or…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also leval · pure-eval · py-expression-eval · simpleeval · cel-expr-python · cel-python · starlark-pyo3 · RestrictedPython · common-expression-language · math-verify