Safe execute expr code.
Project description
📦 perfect-eval
Safe eval module
Installation
pip install -i https://mirrors.aliyun.com/pypi/simple/ --extra-index-url https://pypi.org/simple/ perfect-eval
Example
from perfect_eval import eval_expr
eval_expr("print('hello world')", {"print": print})
# output: hello world
print(eval_expr("now.strftime('%m-%d')", {"now": datetime.now()}))
# output: 10-31
print(eval_expr("a + b", {"a": 123, "b": 456}))
# output: 579
print(eval_expr("f'{a} + {b} = {a + b}'", {"a": 123, "b": 456}))
# output: 123 + 456 = 579
print(eval_expr("match(a, [(1, '11'), (2, '22'), (3, '33')], default='ooo')", {"a": 1}))
# output: 11
print(eval_expr(r"re.sub(r'\d+', '很多', count)", {"count": '10个'}))
# output: 很多个
To Do
- Be the best version of you.
More Resources
- [perfect-eval] on github.com
- Official Python Packaging User Guide
- The Hitchhiker's Guide to Packaging
- Cookiecutter template for a Python package
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file perfect-eval-0.0.10.tar.gz.
File metadata
- Download URL: perfect-eval-0.0.10.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1895bc87bdb393544ab12522da97409096a03592c1b184c865f5f086c5640481
|
|
| MD5 |
9a730246a4a9c3bd6d32d6aa37f34522
|
|
| BLAKE2b-256 |
ad0d3d856722f4354cc43862a5eba1026763b2b9899a861b7c57131dc2ebd12b
|
File details
Details for the file perfect_eval-0.0.10-py3-none-any.whl.
File metadata
- Download URL: perfect_eval-0.0.10-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e921baf1435c2a749a4035bb8ef240024443a277b6cf793f12579253a3341129
|
|
| MD5 |
5a57841522a02586d348eaaa5810eb0c
|
|
| BLAKE2b-256 |
3202838a53691352d789904f9099262999e4c588dee3572c1dc43bf9c4c0e31b
|