pyisheval
pyisheval is a Rust library that allows you to evaluate Python-like expressions.
It's not a full Python interpreter, but it supports a subset of Python-like syntax:
- Arithmetic operations:
+,-,*,/,//,%,**,>,<,>=,<=,==,!= - Variables and assignments
- Lambda expressions (
lambda x: x + 1) - Built-in functions:
abs,max,min,int,float,len,sum - List and dictionary literals
- List comprehensions:
[y * 2 for y in x] - Conditional expressions:
x if x > 5 else 0 - String method:
str.upper(),str.lower(),str.splitlines(), etc. - List method:
list.append(),list.clear(), etc. - Dict method:
dict.clear(),dict.get(),dict.items(),dict.keys(),dict.values(), etc.
No classes, functions (def), or control structures are supported.
Installation
Example
use Interpreter;
Why
This library aims to provide a lightweight and embedded Python-like expression evaluator for scenarios where you want to let users provide arithmetic expressions or simple lambdas without embedding a full Python interpreter.