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 safe_eval

safe_eval("print('11111111')", {"print": print})
# output: 11111111
print(safe_eval("now.strftime('%m-%d')", {"now": datetime.now()}))
# output: 10-28
print(safe_eval("a + b", {"a": 123, "b": 456}))
# output: 579
from perfect_eval import safe_eval, Tmpl

template_str = Tmpl("My name is [name] and my age is [age]")
print(safe_eval(template_str, {"name": "Xiaoming", "age": "17"}))
# output: My name is Xiaoming and my age is 17
template_str = Tmpl("[age] is Xiaoming's age")
print(safe_eval(template_str, {"name": "Xiaoming", "age": "17"}))
# output: 17 is Xiaoming's age
template_str = Tmpl("Xiao Ming's age is [age]")
print(safe_eval(template_str, {"name": "Xiaoming", "age": "17"}))
# output: Xiao Ming's age is 17
template_str = Tmpl("[str(a)] + [str(b)] = [str(a + b)]")
# output: 12 + 13 = 25
template_str = Tmpl("['Have a fever' if temp > 37.5 else 'be free']")
print(safe_eval(template_str, {"temp": 36.6}))
print(safe_eval(template_str, {"temp": 38}))
# output:be free\nHave a fever 

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.3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perfect_eval-0.0.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file perfect-eval-0.0.3.tar.gz.

File metadata

  • Download URL: perfect-eval-0.0.3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for perfect-eval-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0baff6299fc9ba7041da8e78a174c5495c7d3f01f6715106e96647cc4002b9e9
MD5 28b3b3c593702e4c7c88c14dd01865c1
BLAKE2b-256 880e993eaecc4026aa2d5911ffc63c0af3555c4925864ddb0ce109ffe7a0cb11

See more details on using hashes here.

File details

Details for the file perfect_eval-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: perfect_eval-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for perfect_eval-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 32ecd0d0d41f90ddca0a10fe919559a480959c3806d8bc25f84f352850fb0a18
MD5 95d240c74d696a62e8429c31b272fee4
BLAKE2b-256 a1926345b09d654e88a7136ecf8d9523c29318b74f1c8e3ac84a0d538ca7d8c5

See more details on using hashes here.

Supported by

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