Skip to main content

Self-healing Python execution with automatic error recovery and safe execution blocks.

Project description

PyHeal

A self-healing execution library for Python with automatic error recovery, intelligent debugging, and runtime repair.


Features

PyHeal wraps Python execution in a recovery layer:

  • Execute code
  • Detect errors
  • Analyze traceback
  • Apply fixes (if available)
  • Retry execution
  • Recover or restart

Installation

pip install pyheal

Configuration

configure(autofix=False, debug_ai=False, retries=1)

Updates the global configuration settings.

Parameter Type Description
autofix bool Enables automatic fixing mode
debug_ai bool Enables AI-style debug suggestions
retries int Default retry count for healing
configure(
    autofix=True,
    debug_ai=True,
    retries=3
)

Context Managers

skip()

Suppresses all exceptions inside the block.

Useful when you want code to continue even if errors occur.

with skip():
    x = 1 / 0

print("Program continues")
[pyheal] Ignored error: division by zero
Program continues

strict()

Normal Python behavior.

Exceptions are NOT suppressed.

with strict():
    x = 1 / 0

Program crashes normally with traceback.


heal(retries=1)

Attempts to "heal" after an exception occurs.

Currently acts as a retry placeholder system.

Parameter Type Description
retries int Number of healing attempts
with heal(retries=3):
    raise ValueError("Something broke")
[PyHeal] healing attempt 1

If healing fails:

[PyHeal] failed to heal

engine

High-level runtime protection context manager.

Suppresses crashes and logs recovery messages.

with engine():
    x = 1 / 0
[PyHeal ENGINE] started
[PyHeal ENGINE] crash recovered: division by zero

If no error occurs:

[PyHeal ENGINE] finished cleanly

debug_ai()

Provides debugging hints based on exception types.

Error Type Suggestion
ZeroDivisionError Avoid division by zero
IndexError Check list bounds
FileNotFoundError Ensure file exists
with debug_ai():
    x = 1 / 0
[PyHeal DEBUG AI]
Error: division by zero
Suggestion: Avoid division by zero (add validation)

Decorators

@safe(default=None)

Wraps a function safely.

If the function crashes, the error is caught and a default value is returned instead.

Parameter Description
default Value returned when exception occurs
@safe(default=0)
def divide(a, b):
    return a / b

print(divide(10, 0))
[PyHeal SAFE] Caught: division by zero
0

Patch System

apply_patch(error_type, fix)

Registers a runtime patch for an error type.

Parameter Description
error_type Exception class or identifier
fix Patch function or description
apply_patch(
    ZeroDivisionError,
    "Add denominator validation"
)
[PyHeal PATCH] <class 'ZeroDivisionError'> -> Add denominator validation

watch_and_restart(file)

Runs a Python script and automatically restarts it if it crashes.

Parameter Description
file Python file to monitor
watch_and_restart("app.py")
  • Runs the script
  • Detects non-zero exit codes
  • Waits 2 seconds
  • Restarts automatically
[PyHeal] Watching: app.py
[PyHeal] Crash detected. Restarting in 2s...

Internal Classes

Config

Stores global runtime configuration.

Attribute Default
autofix False
debug_ai False
retries 1

PATCHES

Global dictionary storing registered patches.

PATCHES = {
    ZeroDivisionError: "Add validation"
}

Notes

  • heal() currently contains placeholder healing logic.
  • skip() and strict() are implemented twice in the source; the later definitions override the earlier class-based versions.
  • Exceptions inside engine() are always suppressed.
  • debug_ai() provides simple rule-based suggestions rather than real AI debugging.

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyheal-1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

pyheal-1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file pyheal-1.0.tar.gz.

File metadata

  • Download URL: pyheal-1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pyheal-1.0.tar.gz
Algorithm Hash digest
SHA256 3a8a58c6c7f058e97bd5375e8245f71b051c4a381c4de0a324ae87815ac6c513
MD5 9f7fdc910c8d1c9ccda79422f98dab3a
BLAKE2b-256 b3f6c88b3b35e7234c7bdc3a8347dfc2bafd1fc51496ce7a902694bdecd2f93a

See more details on using hashes here.

File details

Details for the file pyheal-1.0-py3-none-any.whl.

File metadata

  • Download URL: pyheal-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pyheal-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce0f4d9bfb47c6c2b1cfb65ec2a7594b2adcde051f263d2f8436b6318a8ef15e
MD5 e5b563da62955d680964411421de10df
BLAKE2b-256 c41bad32d481d8027082b9483a2ebb923672e7aba23b8303eccaa5cfa9aa3407

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