
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
A Python extension module written in Rust that provides bindings to the evalexpr
crate for expression evaluation.
evalexpr
crate (version 12.0.2)PyO3
PyEvalExpr was benchmarked against several popular Python expression evaluation libraries:
Test Case | py_evalexpr | sympy | asteval | simpleeval |
---|---|---|---|---|
simple_arithmetic | 0.0047 ms | 0.2339 ms | 0.0116 ms | 0.0083 ms |
complex_arithmetic | 0.0066 ms | 0.2329 ms | 0.0186 ms | 0.0118 ms |
variables | 0.0046 ms | 0.1996 ms | 0.0126 ms | 0.0083 ms |
math_functions | 0.0077 ms | 0.2403 ms | 0.0230 ms | 0.0117 ms |
complex_expression | 0.0095 ms | 0.2268 ms | 0.0244 ms | 0.0141 ms |
boolean_logic | 0.0059 ms | N/A | 0.0159 ms | 0.0103 ms |
Benchmarks performed on AMD Ryzen 9 7950X with 32GB RAM running Python 3.11 using 50,000 iterations per test. Lower is better.
pip install py-evalexpr
from py_evalexpr import evaluate, evaluate_int, evaluate_float
# Basic arithmetic
result = evaluate("2 + 3 * 4") # Returns 14
result = evaluate("sqrt(16) + 2") # Returns 6.0
# Type-specific evaluation
int_val = evaluate_int("42") # Returns 42 as int
float_val = evaluate_float("3.14159") # Returns 3.14159 as float
bool_val = evaluate_boolean("5 > 3") # Returns True
from py_evalexpr import StatelessContext
context = StatelessContext()
result = context.evaluate("42").value # Integer: 42
result = context.evaluate("sin(0.5)").value # Uses built-in math functions
from py_evalexpr import ImmutableContext
context = ImmutableContext()
context.variables["x"] = 10
context.variables["y"] = 20
result = context.evaluate("x + y").value # Returns 30
from py_evalexpr import MutableContext
context = MutableContext()
context.evaluate_empty("x = 10")
context.evaluate_empty("y = 20")
context.evaluate_empty("sum = x + y")
result = context.evaluate("sum * 2").value # Returns 60
from py_evalexpr import evaluate
from py_evalexpr.exceptions import EvaluationError
try:
result = evaluate("undefined_var + 5")
except EvaluationError as e:
print(f"Evaluation error: {e}")
Contributions are welcome:
Made in 🇨🇦🍁 by Benjamin Kiiskila
FAQs
Python bindings for evalexpr Rust crate for safe expression evaluation
We found that py-evalexpr demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.