📦 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})
print(eval_expr("now.strftime('%m-%d')", {"now": datetime.now()}))
print(eval_expr("a + b", {"a": 123, "b": 456}))
print(eval_expr("f'{a} + {b} = {a + b}'", {"a": 123, "b": 456}))
print(eval_expr("match(a, [(1, '11'), (2, '22'), (3, '33')], default='ooo')", {"a": 1}))
print(eval_expr(r"re.sub(r'\d+', '很多', count)", {"count": '10个'}))
To Do
- Be the best version of you.
More Resources
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.