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.1.tar.gz (4.0 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.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_eval_in_order-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 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.1.tar.gz
Algorithm Hash digest
SHA256 ada10e2a1f1cb8486fd484a23d5464367403aba4d107fef230bc672d252bbb2c
MD5 4f84c02383e1814cbc8d4217da3c3f71
BLAKE2b-256 bd7c18f5bdbed151255f55881a4bea621338b898ec5e6db07191197cf8fbc440

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_eval_in_order-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b21b6d13fa8f80e0a5b57f99fafbc83e1a93a09ec63c9037bacc947c3cd99dc
MD5 82b58d72c71aaec7368693cd0bbd1812
BLAKE2b-256 0ceccaf51fd7b3c99416f86dc17d4df89784b782a7a1dd6cdcb30f4e1bceb3d9

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