etlsrule
English | 中文
安全求值算术表达式,不用 eval。
安装
pip install etlsrule
用法
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
English
Evaluate arithmetic expressions without eval().
Install
pip install etlsrule
Usage
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
Metadata
Release files for etlsrule 0.0.2
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 | |
|---|---|---|---|---|
| etlsrule-0.0.2.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| etlsrule-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / etlsrule-0.0.2.tar.gz
| Download URL | etlsrule-0.0.2.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3aee0735fb256e0fbaf3502bd9b2249efa8c9e51da9d38ecff241a79b3af7ed1
|
|
BLAKE2b-256 checksum How to use checksums |
f025cd9308d791b49430300678d2466b8d0b07eb866195325c6295341d88b112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / etlsrule-0.0.2-py3-none-any.whl
| Download URL | etlsrule-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e70f84d815516f2b31ba5d21a627b56cbf1b4e012bd2d3058b6988230c8ff39
|
|
BLAKE2b-256 checksum How to use checksums |
ad1c8f03d8988102ae73038cb22f41a05fe9dbd26e0e88111e29ad1400a93a7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for etlsrule 0.0.2
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.