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

# Python SDK

> Instrument Python services and supported AI libraries.

Instrument Python services and supported AI libraries.

Start with [ingest key setup](https://docs.struct.ai/observability/instrumentation.md#create-an-ingest-key). Keep credentials in your deployment secret store.

## Configure instrumentation

Install the SDK with the `auto` extra, plus the extra for each AI library you use: `anthropic`, `openai`, `langchain`, `claude-agent-sdk` or `pydantic-ai`.

With struct-sdk 0.4.12 or newer the SDK also instruments OpenAI Chat Completions and streaming calls, and agent frameworks: the `openai-agents`, `mcp`, `google-genai`, `litellm`, `llamaindex` and `autogen` extras, plus CrewAI (1.15.13 or later) and AG2 0.x, which need no extra. Check `pip index versions struct-sdk`: older versions lack some of these, and before 0.4.3 OpenAI coverage is non-streaming Responses calls only.

```bash theme={null}
pip install "struct-sdk[auto,anthropic]"
```

Call `struct.init()` once in each service process, before you import framework classes or create your web app or AI clients. Servers that fork workers (Gunicorn, uWSGI) call it in each worker:

```python theme={null}
import os
from struct_sdk import struct

struct.init(
    ingest_key=os.environ["STRUCT_INGEST_KEY"],
    service_name="checkout-api",
)
```

Or start it without changing code:

```bash theme={null}
OTEL_PYTHON_DISTRO=struct \
STRUCT_INGEST_KEY="pk-..." \
OTEL_SERVICE_NAME=checkout-api \
opentelemetry-instrument python app.py
```

By default the SDK covers your whole service. If your service already has its own OpenTelemetry setup, Struct adds its exporters to your tracer and logger providers and still instruments the supported AI libraries, but adds no full-app instrumentation, no logging bridge and no host metrics. Send host metrics through [Any OpenTelemetry SDK](https://docs.struct.ai/observability/instrumentation/opentelemetry.md) or [Your own collector](https://docs.struct.ai/observability/instrumentation/opentelemetry.md#your-own-opentelemetry-collector). Pass `auto_instrument=False` to send only AI agent calls. AI prompt and answer capture is off unless you turn on `content_capture`; that setting does not filter your app's own log messages, which full-app mode sends.

## Verify the result

Exercise a real operation and follow [signal verification](https://docs.struct.ai/observability/instrumentation.md#verify-instrumentation). Report which signals arrived and which were not configured.


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