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.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.4.1.tar.gz (3.3 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.4.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for openrouter_exception_handler-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ce037bd8288b1d8c3bcb782e4a9587651ceb0d0349745642aa1ddafc29ea2b52
MD5 1f4c2e31c0918ff05323d19261f5b37a
BLAKE2b-256 e2593c2306402138c8b37e4f61f7be12d0573855e2bd73ce86f75128ac2320a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrouter_exception_handler-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 21776379be73402346ac43c4b47e581192f2e301fbe1d22e3a429ad8ce384161
MD5 9ec6850cc5ee6586acea6dce0f0bfd57
BLAKE2b-256 a2a66c3413fb3fa15000afc383e1adf4fbab3a17660047fa8482ab9d7202c3d2

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