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.3.tar.gz (5.5 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.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_eval_in_order-0.1.3.tar.gz
  • Upload date:
  • Size: 5.5 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.3.tar.gz
Algorithm Hash digest
SHA256 db49958f8b6a8eb12b559cc336737d24195b36c3dc9f03b95a67116eac7ab086
MD5 1335c4765c190d2816eb7e8f7eb2bf3f
BLAKE2b-256 14a6e69b899ad21059e3c294bf86fd3b10ea426aab24e1af317aa56e32592556

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_eval_in_order-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a1f33c27f913e2d1ffe30edd61de848d3c543be2813f11400f308679c4b220fa
MD5 ef511dd7e609a4a37b6c98b7a9ea0a33
BLAKE2b-256 4a045e03b636cab21b8c77c467b78700833fbfef412a6fcde7bdfaa36fbf5677

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