Skip to main content
https://github.com/lmfit/asteval/actions/workflows/ubuntu_numpy.yml/badge.svg https://github.com/lmfit/asteval/actions/workflows/ubuntu_nonumpy.yml/badge.svg https://github.com/lmfit/asteval/actions/workflows/macos_numpy.yml/badge.svg https://github.com/lmfit/asteval/actions/workflows/windows_numpy.yml/badge.svg https://codecov.io/gh/lmfit/asteval/branch/master/graph/badge.svg https://img.shields.io/pypi/v/asteval.svg https://img.shields.io/pypi/dm/asteval.svg https://img.shields.io/badge/docs-read-brightgreen https://zenodo.org/badge/4185/newville/asteval.svg

Installation

Use pip install asteval to install the asteval library.

Asteval supports Python 3.10 or higher. No modules outside of the standard library are required, though if NumPy is installed, many functions from it will be used by default.

About Asteval

Asteval is a safe(ish) evaluator of Python expressions and statements, using Python’s ast module. It provides an easy-to-use restricted Python interpreter that supports a pretty complete subset of the Python language and can handle user input more safely than Python’s eval(). Asteval emphasizes mathematical expressions so that many functions from NumPy are imported and used if available, but also provides a pretty complete subset of the Python language. It can be used as an embedded macro language within a large application or as a simple calculator for mathematical calculations.

Asteval supports many Python language constructs by default, including conditionals (if-elif-else blocks and if expressions), flow control (for loops, while loops, with blocks, and try-except-finally blocks), list comprehension, slicing, subscripting, and f-strings. All data are Python objects and the standard built-in data structures (dictionaries, tuples, lists, sets, strings, functions, and Numpy nd-arrays) are well supported, and most public attributes and methods of these objects are available. Asteval does place some limitations on “looking under the hood” to get private and potentially unsafe methods.

Many of the standard built-in Python functions are available, as are the functions from the math module. Some built-in operators and functions, such as getattr, and setattr are not allowed, and some including open and ** are replaced with versions intended to make them safer for user input. If the NumPy is installed, many of its functions will also be available. Programmers can add custom functions and data of their own into each Asteval session. Users can define and run their own functions within the confines of the limitations of the Asteval language.

Asteval converts user input into Python’s own abstract syntax tree (AST) representation and determines the result by walking through that tree. This approach guarantees the parsing of input will be identical to that of Python, eliminating many lexing and parsing challenges and generating a result that is straightforward to interpret. This makes “correctness” easy to test and verify with high confidence, so that the emphasis can be placed on balancing functionality with safety.

There are several absences and differences with Python, and Asteval is by no means an attempt to reproduce Python with its own ast module. While, it does support a large subset of Python, the following features found in Python are not supported in Asteval:

  1. creating classes is not supported

  2. many internal methods and classes of Python objects, especially __dunder__ methods cannot be accessed.

  3. eval, exec, yield, async, match/case, function decorators, generators, and type annotations are not supported.

  4. f-strings are supported, but t-strings are not supported.

  5. importing modules is not supported by default, though it can be enabled.

Most of these omissions and limitations are intentional, and aimed to strengthen Asteval against dangerous user code. A few of these (say, match/case and t-strings) omissions may simply be viewed as not particularly compelling need for an embedded interpreter exposed to user input.

Even with these restrictions, Asteval provides a pretty complete and usable scripting or “macro” language that can easily be embedded into a larger GUI or Web application that can handle user input without many of the risks associated with using Python’s eval().

Matt Newville <newville@cars.uchicago.edu> Last Update: 17-Dec-2025

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asteval-1.0.10.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asteval-1.0.10-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file asteval-1.0.10.tar.gz.

File metadata

  • Download URL: asteval-1.0.10.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for asteval-1.0.10.tar.gz
Algorithm Hash digest
SHA256 46a4ed13cc2e4a29a21418f89dedd57db70d98eb96db0fb4c441d4edb2f5afed
MD5 b0ffe26b90e954327c04a9f6b404ba97
BLAKE2b-256 659ae10e062c83de2219c5f9ef9d684dac39323c052de140e257afd0f60f8ca7

See more details on using hashes here.

File details

Details for the file asteval-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: asteval-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for asteval-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 8d805fa8084aa12204715f799430f0012a0db38b42e997f9f11a9637ad59855f
MD5 ac6c60f62ea679ee123ba7813d4a54ad
BLAKE2b-256 9216e78d6e60ecd1b3cf446fad45985ad6cda22f46ad2cffabb644d77b317bc4

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.10 This release

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.9.33

2 files

0.9.32

2 files

0.9.31

2 files

0.9.30

2 files

0.9.29

2 files

0.9.28

2 files

0.9.27

2 files

0.9.26

1 file

0.9.25

1 file

0.9.24

1 file

0.9.23

1 file

0.9.22

1 file

0.9.21

1 file

0.9.20

1 file

0.9.19

1 file

0.9.18

1 file

0.9.17

1 file

0.9.16

1 file

0.9.15

1 file

0.9.14

1 file

0.9.13

1 file

0.9.12

1 file

0.9.11

1 file

0.9.10

1 file

0.9.9

1 file

0.9.8

1 file

0.9.7

1 file

0.9.6

0.9.5

3 files

0.9.4

0.9.3

2 files

0.9.2

4 files

0.9.1

4 files

0.9

4 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page