py-expression-eval
Python Mathematical Expression Evaluator
What it is and what it does
py-expression-eval is a mathematical expression parser and evaluator ported from a JavaScript library. It takes mathematical expressions as strings and converts them into evaluable objects that can be computed with variable substitution. The library supports standard arithmetic operators, trigonometric and logarithmic functions, boolean logic, and constants like PI and E.
You create a Parser instance, call parse() on an expression string to get an Expression object, then evaluate() it with a dictionary of variable values. The library also offers simplification (reducing expressions algebraically), substitution (replacing variables with other expressions), and variable extraction. It's useful for applications that need to accept user-supplied or configuration-based mathematical formulas without executing arbitrary code.
Use it for:
- Accept mathematical formulas from users in web forms or configuration files and compute results safely
- Build spreadsheet-like applications where cells contain formulas referencing other cells
- Implement rule engines or business logic systems that rely on user-defined mathematical conditions
- Validate and simplify mathematical expressions in educational or scientific tools
- Generate dynamic calculations in data processing pipelines where formulas are stored as strings
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses and evaluates mathematical expressions from strings, supporting arithmetic, trigonometric, logarithmic functions, and variables with substitution and simplification.
Yes, if you need a lightweight, dependency-free expression evaluator for a stable use case. The package is mature and has no known vulnerabilities. However, do not use it for new projects requiring active maintenance or support—the repository is archived and the last commit was 2022-06-11. For actively maintained alternatives or complex symbolic math, consider other options.
Install
py-expression-eval on PyPI
pip
pip install py-expression-evaluv
uv add py-expression-evalpoetry
poetry add py-expression-evalInstalling py-expression-eval
Before you install
Installation is straightforward with no runtime dependencies. However, the repository is archived and the last commit was 2022-06-11, indicating the project is no longer actively maintained.
License in practice
Licensed under MIT (permissive), allowing free use, modification, and distribution with minimal restrictions.
Quickstart
pip install py-expression-eval
from py_expression_eval import Parser
parser = Parser()
result = parser.parse('2 * x + 1').evaluate({'x': 3})
print(result) # 7
Verify before relying
- Whether the package handles edge cases in expression parsing (division by zero, invalid syntax) gracefully
- Performance characteristics when evaluating complex nested expressions or with many variables
- Compatibility with Python versions beyond 3.9, given the latest release predates newer Python versions
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,814 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 150,894/month — #10,951 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: py_expression_eval-0.3.14-py3-none-any.whl
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
astevalAsteval is a safe Python expression and…
permissive · top 5,000 on PyPI
jsonata-pythonEvaluates JSONata expressions against JSON…
permissive · top 5,000 on PyPI
simpleevalEvaluates mathematical and logical expressions…
permissive · top 5,000 on PyPI
math-verifyEvaluates mathematical expressions from LLM…
permissive · top 5,000 on PyPI
levalLeval evaluates limited expressions safely by…
permissive · top 15,000 on PyPI
boolean.pyParse, simplify, and compare boolean…
permissive · top 1,000 on PyPI
envsubstSubstitutes environment variables in strings…
permissive · top 15,000 on PyPI
pure-evalSafely evaluate Python AST nodes without…
permissive · top 1,000 on PyPI
tag-expressionsParses and evaluates logical tag expressions…
copyleft · top 15,000 on PyPI
cel-expr-pythonA Python wrapper for the CEL C++ implementation…
permissive · top 15,000 on PyPI