Minimal. Single function. No dependencies. You give a string with a numeric expression; it returns a float.
Install
pip install expreval
Quick use
from expreval import evaluate
evaluate("sin(pi/2) + log(e)") # 2.0
CLI:
expreval "sin(pi/4)**2"
What works now
- Numbers: int / float literals
- Operators: + - * / % ** and unary + -
- Grouping: ( )
- Names: pi, e, any function from the standard
mathmodule (sin, cos, sqrt, log, ...) - Simple function calls with positional arguments only
That is all - for now.
Safety (current scope)
Only a hand‑written walk over Python's ast for a very small subset. No attribute access, no imports, no keywords, no assignments, no lambdas, no comprehensions. If it's not listed above it should raise an error.
API
evaluate(expression: str) -> float
Returns a float (even if you pass an int literal). Raises standard Python exceptions (NameError, TypeError, etc.) for invalid input.
Examples
evaluate("2*(3+4)-5/2") # 11.5
evaluate("sin(pi/6)**2") # 0.249999... (floating point)
evaluate("sqrt(2)**2") # 2.000000...
Why
Original itch: certain very large numeric expressions (or results) caused numexpr to raise errors in our workflow. For simple scalar math that shouldn't fail, we just needed a tiny, predictable evaluator that:
- Has zero heavy dependencies
- Doesn't optimize or chunk arrays (so no surprise shape / size limits)
- Always returns a plain Python float for valid math
- Is easy to audit (a short AST walk) and extend later if truly needed
So expreval exists to reliably handle those "big result" cases where bringing in numexpr (and hitting its internal limits) was overkill. If you only need quick scalar math, this keeps it boring and dependable.
Contributor Guide
uv venv
uv sync
# make changes and then run these
# to create coverage logo and changelogs
.\scripts\update.sh
# (Optional)to bump version for release
uv run scripts\bump_version.py <X.Y.Z>
License
MIT. See LICENSE.
Metadata
Release files for expreval 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| expreval-1.1.0.tar.gz | 3.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| expreval-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / expreval-1.1.0.tar.gz
| Download URL | expreval-1.1.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce4bcc462973e888349ac8e37976d7c0d65deab6a71254821077962c11da696e
|
|
BLAKE2b-256 checksum How to use checksums |
99dd1be1d763d8bd0fa06e89419d2728993d347be3b8945f00edadabb0b7c2ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / expreval-1.1.0-py3-none-any.whl
| Download URL | expreval-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2e5d58f6683e1876980fc663b3abb65a5064c88b0d7b258f861536323bfa01b
|
|
BLAKE2b-256 checksum How to use checksums |
f8924813c5e18a6cf9606857b39da66432afcae33179fd3c1b91018b5c77b85e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for expreval 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.