Skip to main content

A Python package for evaluating multiple boolean conditions (uses eval) IN ORDER.

Project description

py_eio_logic

A simple Python package for evaluating multiple boolean conditions provided as strings.

WARNING: This package uses eval() internally. It is EXTREMELY DANGEROUS to use this package with UNTRUSTED INPUT STRINGS. Malicious input can lead to arbitrary code execution on your system. Please ensure all conditions passed to eio() are from trusted, internal sources only.

Installation

pip install py-eval-in-order

from py_eio_logic import eio

# Example 1: Passing individual condition strings
x = 10
y = 5
result = eio("x > 5", "y < 10")
print(f"Result 1: {result}") # Expected: True

result = eio("x == 10", "y == 6")
print(f"Result 2: {result}") # Expected: False

# Example 2: Passing a list of condition strings
z = 7
conditions_list = ["z >= 7", "x + y == 15"]
result = eio(conditions_list)
print(f"Result 3: {result}") # Expected: True

conditions_list_fail = ["z < 5", "x > 0"]
result = eio(conditions_list_fail)
print(f"Result 4: {result}") # Expected: False

# Example 3: When no conditions are passed (evaluates to True)
result = eio()
print(f"Result 5: {result}") # Expected: True


from py_eio import eio

# 'undefined_var' does not exist.
# The second condition would cause a NameError if evaluated.

# Case 1: Error condition is after a False condition
result = eio("1 == 2", "undefined_var > 0")
print(f"Result with error condition after False: {result}")
# Output: Result with error condition after False: False
# (No error message for 'undefined_var' because "1 == 2" is False, and evaluation stops)

# Case 2: Error condition is the first one, or after a True condition
# This will print an error message from the function (due to the try-except block)
# and return None.
result = eio("1 == 1", "another_undefined_var > 0")
print(f"Result with error condition evaluated: {result}")
# Output: Error evaluating condition 'another_undefined_var > 0': name 'another_undefined_var' is not defined
#         Result with error condition evaluated: False

git clone [https://github.com/MostafaHanii/py_eio.git](https://github.com/MostafaHanii/py_eio.git)
cd py_eio
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e .

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

py_eval_in_order-0.1.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

py_eval_in_order-0.1.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file py_eval_in_order-0.1.2.tar.gz.

File metadata

  • Download URL: py_eval_in_order-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for py_eval_in_order-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f68ef5fde7064a55bf361e2e4b08c9fdba0e89e43d2626700371852db65ac4cf
MD5 0cf16b4410610aa987a58b3a3bac01df
BLAKE2b-256 94c8657151f1291ec7b6a600c6acd8c2c8a938cf1e647b0e66ae6604866b9587

See more details on using hashes here.

File details

Details for the file py_eval_in_order-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for py_eval_in_order-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 de2fbba8bf3786909e26ddba6d4de8b9ed5633060aedb19475f9fb4aa3ee0e56
MD5 735023593089be10becf60297f9b04c8
BLAKE2b-256 29b027696a67c66b25e287fb4113db3988212e1e9d9b8c4715c2f613ac3dc57f

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