Skip to main content

Safe, minimalistic evaluator of python expression using ast module

Project description

https://travis-ci.org/newville/asteval.png

What is it?

ASTEVAL is a safe(ish) evaluator of Python expressions and statements, using Python’s ast module. The idea is to provide a simple, safe, and robust miniature mathematical language that can handle user-input. The emphasis here is on mathematical expressions, and so numpy functions are imported and used if available.

While much of Python’s constructs are supported, there are important absences and differences, and this is by no means an attempt to reproduce Python with its own ast module. Important differences and absences are:

  1. Variable and function symbol names are held in a simple symbol table (a single dictionary), giving a flat namespace.
  2. creating classes is not supported.
  3. importing modules is not supported.
  4. function decorators, yield, lambda, and exec are not supported.

Many built-in python syntactical components (if-then-else, while loops, for loops, try-except blocks, list comprehension, slicing, subscripting), and built-in data structures (dictionaries, tuple, lists, numpy arrays, strings) are fully supported. In addition, many built-in functions are supported, including the standard builtin python functions, and all mathemetical functions from the math module. As mentioned above, if numpy is available, many of its functions will also be available. Users can define their own functions, but given the restrictions of not being able to define classes or import modules, the language is decidedly limited.

Project details


Download files

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

Files for asteval, version 0.9.3
Filename, size File type Python version Upload date Hashes
Filename, size asteval-0.9.3-py2-none-any.whl (14.0 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size asteval-0.9.3.tar.gz (29.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page