simpleeval
A simple, safe single expression evaluator library.
What it is and what it does
simpleeval is a lightweight library that safely evaluates mathematical and logical expressions provided as strings, without exposing the full power and security risks of Python's eval(). It uses Python's ast module to parse expressions and enforce strict limits on what operations are allowed, making it suitable for scenarios where you want to let users or configuration systems define formulas—such as setting alarm volumes based on time of day, or allowing simple math in web forms—without granting arbitrary code execution.
The library comes with sensible defaults: basic arithmetic, comparison, and bitwise operators; a handful of utility functions like randint(), int(), float(), and str(); and configurable limits on exponentiation and string length to prevent denial-of-service attacks. You can extend it by passing custom functions and variables (called 'names') into the evaluator, or by replacing operators entirely. It's deliberately kept simple and single-file, so you can even embed it directly in a project if you prefer not to add a dependency.
Use it for:
- Allow users to define alarm volume rules that depend on time of day, alarm level, and other state without risking code injection.
- Accept simple mathematical formulas in web forms or configuration files and evaluate them safely server-side.
- Build rule engines or conditional logic systems where non-technical users can write expressions like 'if x > 10 then y else z'.
- Implement dynamic pricing or discount calculations in e-commerce systems based on user-provided or admin-configured formulas.
- Parse and evaluate mathematical expressions in scientific or educational applications without the security overhead of full eval().
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Evaluates mathematical and logical expressions from strings in a safe, sandboxed way without using Python's built-in eval(), letting you add user-configurable formulas to applications.
Yes. The package is mature, has no dependencies, carries no known vulnerabilities, and solves a real security problem—allowing safe user-defined expressions. Install it if you need to evaluate untrusted formulas; avoid it only if you need features beyond basic arithmetic, comparisons, and simple function calls, or if you're not concerned about the security implications of eval().
Install
simpleeval on PyPI
pip
pip install simpleevaluv
uv add simpleevalpoetry
poetry add simpleevalInstalling simpleeval
Before you install
No runtime dependencies and a single-file design keep installation friction minimal. The package is actively maintained with a recent release, and has been stable since its initial 2014 release.
License in practice
MIT license is permissive and imposes no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
from simpleeval import simple_eval
result = simple_eval("21 + 21")
print(result) # 42
# With custom functions
result = simple_eval("square(11)", functions={"square": lambda x: x*x})
print(result) # 121
Requires Python 3.9 or later.
Verify before relying
- Whether the default MAX_POWER limit of 4000000 and MAX_STRING_LENGTH of 100000 characters are appropriate for your use case.
- Whether the package's DOS protection against long-running or memory-intensive expressions is sufficient for your deployment context.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 151 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 15,002,011/month — #1,206 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: simpleeval-1.0.7-py3-none-any.whl
Keywords: ast, eval, expression, parse, simple
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
astevalAsteval is a safe Python expression and…
permissive · top 5,000 on PyPI
levalLeval evaluates limited expressions safely by…
permissive · top 15,000 on PyPI
py-expression-evalParses and evaluates mathematical expressions…
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
boolean.pyParse, simplify, and compare boolean…
permissive · top 1,000 on PyPI
cel-pythonParses and evaluates Google Common Expression…
unclear · top 5,000 on PyPI
common-expression-languageEvaluates Google's Common Expression Language…
permissive · top 15,000 on PyPI
math-verifyEvaluates mathematical expressions from LLM…
permissive · top 5,000 on PyPI