Skip to main content

Handler for exceptions in Python with OpenRouter.ai

Project description

OpenRouter Exception Handler

A Python module distributed via pip that automatically handles exceptions using intelligent responses generated by OpenRouter.ai.

🚀 Installation

pip install openrouter_exception_handler

📌 Features

  • Automatically captures Python exceptions during execution.
  • Sends exception details to OpenRouter.ai.
  • Displays intelligent responses from OpenRouter.ai directly in your stdout.
  • Facilitates AI-assisted debugging, reducing the time needed for error diagnosis.

🔧 Quick Usage

Simply decorate your functions with @exception_handler:

from openrouter_exception_handler import exception_handler

@exception_handler
def divide(a, b):
    return a / b

divide(10, 0)  # Will trigger ZeroDivisionError

Example Output

❌ Exception captured:
Traceback (most recent call last):
  File "example.py", line 6, in wrapper
    return func(*args, **kwargs)
  File "example.py", line 10, in divide
    return a / b
ZeroDivisionError: division by zero

AI Response:
This exception occurs because you're trying to divide by zero. Validate your inputs before performing division to prevent this error.

🔑 Configuration

Define your OpenRouter.ai API key in the environment variable APIKEY_OPENROUTER:

export APIKEY_OPENROUTER="your_api_key_here"

📦 Installation

Install easily using pip:

pip install openrouter_exception_handler

📌 Requirements

  • Python >= 3.6
  • requests

📄 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

openrouter_exception_handler-0.2.4.tar.gz (2.1 kB view details)

Uploaded Source

Built Distribution

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

openrouter_exception_handler-0.2.4-py3-none-any.whl (2.0 kB view details)

Uploaded Python 3

File details

Details for the file openrouter_exception_handler-0.2.4.tar.gz.

File metadata

File hashes

Hashes for openrouter_exception_handler-0.2.4.tar.gz
Algorithm Hash digest
SHA256 a13bdd6b7138985637d6395cf35aa2514346757ee96720210af744880a739375
MD5 9ba29c7c7b5c63560c00bd8a1126f929
BLAKE2b-256 8911a7e6e25540d18d3a7f110a5d678c98c3b6adf99e11381bf395fb50f32193

See more details on using hashes here.

File details

Details for the file openrouter_exception_handler-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for openrouter_exception_handler-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 42e16c3627688576fcfcb974c93de3835d4fad8014dbc516d2ff610745a91b51
MD5 4bddcc672832034a63ef2e67e75e7126
BLAKE2b-256 f95a4ae2d96b734cd5f365a874c5782c2cf89a1c99787fb75229edf2f272764b

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