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


Here's a simple guide to create an API key on OpenRouter

  1. Sign Up or Log In Go to openrouter.ai and create an account, or log in if you already have one.

  2. Go to Your User/Developer Settings Look for a section like Developer Settings, API Keys, or Settings in your account dashboard.

  3. Generate a New Key

    • Click Generate New Key (or a similar button) to create your new API key.
    • Copy the generated API key. Note that for security reasons, you usually only get to see the key once.
  4. Save Your API Key

    • Store it in a safe place (e.g., an environment variable or a password manager).
    • Avoid committing it directly to a public repository or version control.

Tip: Once you have your API key, set it in your environment (e.g., OPENROUTER_API_KEY), so your application can access it securely without exposing it in the source code.

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for openrouter_exception_handler-0.4.3.tar.gz
Algorithm Hash digest
SHA256 18ee863423200a9deae1b952814ec40a86d393666c117ebb57b74c3260c0f3a5
MD5 1d5557b8363166ee559ab1c7891f15b2
BLAKE2b-256 f9c0bdbcfc220f9080355dec421deffaa00e577caf3a45ea7b1856ead8e10320

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrouter_exception_handler-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e89d8af03af94a7254a21ce11c43d36ca90d044388be08f0657331f41f6becb0
MD5 7500d6c73c847e62c56757f440ac20a5
BLAKE2b-256 ab7bea6262a52fc82221fd622aadb30e77ab85459365d74001c58be7aa65c8df

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