Skip to main content

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.

Release files for PyHeal 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyHeal 1.0
File Size Uploaded
pyheal-1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyHeal 1.0
File Interpreter ABI Platform
pyheal-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / pyheal-1.0.tar.gz

Download URL pyheal-1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3a8a58c6c7f058e97bd5375e8245f71b051c4a381c4de0a324ae87815ac6c513
BLAKE2b-256 checksum
How to use checksums
b3f6c88b3b35e7234c7bdc3a8347dfc2bafd1fc51496ce7a902694bdecd2f93a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / pyheal-1.0-py3-none-any.whl

Download URL pyheal-1.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce0f4d9bfb47c6c2b1cfb65ec2a7594b2adcde051f263d2f8436b6318a8ef15e
BLAKE2b-256 checksum
How to use checksums
c41bad32d481d8027082b9483a2ebb923672e7aba23b8303eccaa5cfa9aa3407
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page