Skip to main content

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perfect-eval-0.0.10.tar.gz (16.3 kB view hashes)

Uploaded Source

Built Distribution

perfect_eval-0.0.10-py3-none-any.whl (9.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page