Skip to main content

Automatically trace function execution and generate flowcharts with a Python decorator

Project description

Logikit

Automatically trace function execution and generate flowcharts with a Python decorator

Installation

Local Installation (Development)

From the project root:

cd logikit
pip install -e .

Or directly from the project root:

pip install -e ./logikit

PyPI Installation

pip install logikit

Usage

Basic Usage

from logikit import logikit

class MyChecker:
    @logikit(condition_map={
        "_fails_regulated_area_rules": "Check regulated area requirements",
        "_fails_public_housing_zone_rules": "Check public housing zone requirements",
        "_has_invalid_account": "Check account validity",
    })
    def is_eligible(self):
        if self._fails_regulated_area_rules():
            return False
        if self._fails_public_housing_zone_rules():
            return False
        if self._has_invalid_account():
            return False
        return True

    def _fails_regulated_area_rules(self):
        # Actual condition check logic
        return False

    def _fails_public_housing_zone_rules(self):
        return False

    def _has_invalid_account(self):
        return False

Accessing Trace

After function execution, you can access the trace from the instance's _logikit_trace attribute:

checker = MyChecker()
result = checker.is_eligible()

# Access trace
trace = checker._logikit_trace
for step in trace:
    print(f"{step.label}: {'PASS' if step.passed else 'FAIL'}")

Generating Flowcharts

from logikit import generate_flowchart_from_trace

checker = MyChecker()
result = checker.is_eligible()

# Generate Mermaid flowchart code
mermaid_code = generate_flowchart_from_trace(checker._logikit_trace)
print(mermaid_code)

How It Works

  1. The @logikit decorator parses the function's source code to identify the order of conditional statements.
  2. During function execution, each condition is evaluated sequentially and results are traced.
  3. The trace is stored in the instance's _logikit_trace attribute.
  4. You can generate Mermaid flowchart code using the generate_flowchart_from_trace() function.

License

MIT

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

logikit-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

logikit-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file logikit-0.1.0.tar.gz.

File metadata

  • Download URL: logikit-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for logikit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 16e88c942497120a444fd9d59067107d5793d5704700adc124d889ab1b217f2e
MD5 b16aa81b8db7c33c59cc4ef4f03dca4b
BLAKE2b-256 be9b57c6eb62ed8166fac6c3ae5efc9769cb66e22e48a539a596dc2ee4286bf4

See more details on using hashes here.

File details

Details for the file logikit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: logikit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for logikit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19ee266b343847be7af45a0acf44461bc6698166c757a142b3dec092232c4fb4
MD5 ac20e339def4f13020bd0232dce529b6
BLAKE2b-256 0f8f023e5907d55c60414ad019d1dc62bc2d00eb0885a06ebad6edaacd58981d

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