> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lunary.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK Reference

## Classes

| Class | Description |
| - | - |
| `EventQueue` | A class that represents a queue of events. |
| `Consumer` | A class that consumes events from the `EventQueue`. |
| `UserContextManager` | A context manager for setting and resetting user context. |

## Methods

| Method | Description |
| - | - |
| `config(app_id: str \| None = None, verbose: str \| None = None, api_url: str \| None = None, disable_ssl_verify: bool \| None = None)` | Configures the SDK with the given parameters. |
| `track_event(event_type: str, event_name: str, run_id: uuid, parent_run_id: uuid, name: str, input: Any, output: Any, error: Any, token_usage: Any, user_id: str, user_props: Any, tags: Any, extra: Any) -> None` | Tracks an event with the given parameters. |
| `handle_internal_error(e: Exception) -> None` | Handles internal errors. |
| `wrap(fn: Callable, type: str, name: str, user_id: str, user_props: Any, tags: Any, input_parser: Callable, output_parser: Callable) -> Callable` | Wraps a function with monitoring capabilities. |
| `monitor(object: OpenAIUtils) -> None` | Monitors an instance of `OpenAIUtils`. |
| `identify(user_id: str, user_props: Any) -> UserContextManager` | Identifies a user and sets the user context. |

## Decorators

| Decorator | Description |
| - | - |
| `agent(name: str, user_id: str, user_props: Any, tags: Any) -> Callable` | A decorator for marking a function as an agent. |
| `tool(name: str, user_id: str, user_props: Any, tags: Any) -> Callable` | A decorator for marking a function as a tool. |

## Context Variables

| Variable | Description |
| - | - |
| `user_ctx` | A context variable for storing the user ID. |
| `user_props_ctx` | A context variable for storing user properties. |

## Environment variables

| Variable | Description |
| - | - |
| `LUNARY_PUBLIC_KEY` | Your project's public key |
| `LUNARY_PRIVATE_KEY` | Your project's private key |
| `LUNARY_VERBOSE` | Set to `true` or `True` before importing `lunary` to enable verbose logging. Leave unset or set to `false` for normal logging. |
| `LUNARY_API_URL` | Base URL for the API server. Defaults to `https://api.lunary.ai`; can be customized for self-hosting or local use. |
| `DISABLE_SSL_VERIFY` | Disable SSL verification if set to `True` |

## Diagnosing event delivery errors

To interpret a failed batch and choose what to check next, see [Read a production error](https://docs.lunary.ai/integrations/python/logging.md#read-a-production-error). The guide includes HTTP responses, missing keys, connection and TLS errors, timeouts, and encoding failures.

### Verbose logging

See [Trace batch activity](https://docs.lunary.ai/integrations/python/logging.md#trace-batch-activity-without-logging-event-contents) for consumer-only DEBUG output or [Use verbose logging for one reproduction](https://docs.lunary.ai/integrations/python/logging.md#use-verbose-logging-for-one-reproduction) for event details and tracebacks.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.