Skip to main content

Python SDK

DebuggAI's Python SDK provides powerful logging and monitoring capabilities for your AI applications. This guide will help you get started with the Python SDK.

Installation

Install the DebuggAI Python SDK using pip:


pip install debugg-ai-sdk

Prerequisites

Before using the DebuggAI Python SDK, make sure you have:

  • Python 3.6 or later
  • An API key from DebuggAI (sign up at app.debugg.ai)

Basic Usage

Here's a simple example of how to use the DebuggAI Python SDK:

from debugg_ai_sdk import DebuggAiLogger

# Initialize the SDK with your API key
debugg = DebuggAiLogger(
ingest_url="your-ingest-url",
host_name="username_host-location",
environment="production", # production | staging | development | local
log_level="INFO", # DEBUG, INFO, WARNING, ERROR
)


# The function will now automatically log:
# - Input prompts
# - Output responses
# - Performance metrics
# - Any errors that occur

Advanced Configuration

Custom Logging

You can customize what gets logged by configuring the SDK:

debugg = DebuggAiLogger(
# ...config from above
# Optional configuration
redact_sensitive=True # Automatically redact sensitive information
)

Context Management

Add context to your logs using the context manager:

log.info('Your message', user_id="123", session_id="abc"):

Manual Logging

You can also log events manually:

# Log an error
try:
# Your code here
pass
except Exception as e:
log.error(e, context={"step": "processing"})


# OR
try:
# Your code here
pass
except Exception as e:
debugg.error(e, context={"step": "processing"})

Best Practices

  1. Initialize Early: Initialize the SDK as early as possible in your application
  2. Add Context: Use context managers to add relevant information to your logs
  3. Handle Errors: Always log errors with appropriate context
  4. Monitor Performance: Use the monitoring decorator for AI functions
  5. Redact Sensitive Data: Enable redaction for production environments

Troubleshooting

If you encounter issues:

  1. Check your API key is valid
  2. Verify your Python version meets the requirements
  3. Ensure you have network connectivity
  4. Check the SDK logs for detailed error messages

Next Steps

  • Learn about Error Tracing to see how DebuggAI helps you debug issues
  • Explore Analytics to understand your AI application's performance
  • Check out Click to Fix to automatically fix common issues