Metadata-Version: 2.5
Name: etlsrule
Version: 0.0.2
Summary: 安全求值算术表达式，不用 eval。
Project-URL: Homepage, https://pypi.org/project/etlsrule/
Author-email: lqxnjk <lqxnjk@qq.com>
License: MIT
License-File: LICENSE
Keywords: arithmetic,ast,evaluate,expression,safe
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# etlsrule

[English](#english) | 中文

安全求值算术表达式，不用 eval。

## 安装

```console
pip install etlsrule
```

## 用法

```python
from etlsrule import evaluate

evaluate("1 + 2 * 3")                       # 7.0
evaluate("x * y", {"x": 3, "y": 4})         # 12.0
evaluate("a > b", {"a": 2, "b": 1})         # True

evaluate("__import__('os')")                # ValueError
```

## 说明

只支持数字、变量名、四则运算、幂、比较与括号，用 `ast` 仅放行允许的节点；出现任何其它语法（调用、属性访问、下标、字符串）一律抛 `ValueError`。变量缺失同样抛错，不当作 0。

## 许可证

MIT

---

<a id="english"></a>
## English

Evaluate arithmetic expressions without eval().

## Install

```console
pip install etlsrule
```

## Usage

```python
from etlsrule import evaluate

evaluate("1 + 2 * 3")                       # 7.0
evaluate("x * y", {"x": 3, "y": 4})         # 12.0
evaluate("a > b", {"a": 2, "b": 1})         # True

evaluate("__import__('os')")                # ValueError
```

## Notes

Only numbers, variable names, `+ - * / // % **`, comparisons and parentheses are accepted, parsed through an `ast` allow-list of node types. Anything else — calls, attribute access, subscripts, strings — raises `ValueError`, and a missing variable raises instead of defaulting to zero.

## License

MIT
