Skip to main content

Respan Python SDK

respan.ai | Documentation | PyPI

respan-ai is the unified Python entry point for Respan tracing, decorators, context propagation, and first-party instrumentation plugins. It automatically discovers eligible direct LLM SDK adapters while keeping frameworks, agents, wrappers, and observability bridges explicit to avoid duplicate spans.

Requirements

  • Python 3.11, 3.12, or 3.13
  • A Respan API key for telemetry export
  • The provider SDK used by your application

Installation

Install the facade and your provider SDK. For OpenAI:

pip install respan-ai openai

With Poetry:

poetry add respan-ai openai

Replace openai with the provider SDK your application uses. respan-ai already bundles the supported first-party instrumentation adapters and respan-tracing; provider SDKs remain application-owned dependencies.

Automatic Onboarding

Set your Respan credentials:

export RESPAN_API_KEY="your-api-key-here"
# Optional; this is also the Respan gateway base URL used below.
export RESPAN_BASE_URL="https://api.respan.ai/api"

Construct Respan before the first provider call. Python discovery and activation happen synchronously in the constructor, so there is no separate initialize() call:

import os

from openai import OpenAI
from respan import Respan

# Omit `instrumentations` to use curated direct-LLM automatic discovery.
respan = Respan()

client = OpenAI(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
)

response = client.chat.completions.create(
    model="gpt-4.1-nano",
    messages=[{"role": "user", "content": "Say hello in three languages."}],
)
print(response.choices[0].message.content)

print(respan.get_auto_instrumentation_status())
respan.shutdown()

This example routes inference through the Respan gateway. When calling a provider directly, configure that provider's credentials and endpoint normally; Respan still reads RESPAN_API_KEY for telemetry export.

Automatically Supported Providers

The facade bundles these adapters. Install only the provider SDKs your application actually imports.

Provider Application SDK
OpenAI and Azure OpenAI openai
Anthropic anthropic
Vertex AI google-cloud-aiplatform
Google GenAI google-genai
AWS Bedrock boto3
Together AI together
Ollama ollama

Only registry entries classified as direct LLM integrations and enabled by default are activated. A missing provider SDK is reported as missing and does not stop application startup. Broad OpenTelemetry entry-point discovery remains disabled.

Inspect Instrumentation Status

for entry in respan.get_auto_instrumentation_status():
    print(entry["id"], entry["status"], entry.get("reason"))

Each entry includes the registry ID, runtime name, provider, provider SDK, instrumentation package, status, and optional reason. Status is one of enabled, disabled, missing, or failed.

The dataclass form is also available as respan.auto_instrumentation_status.

Control Automatic Discovery

Disable automatic discovery completely:

from respan import Respan

respan = Respan(is_auto_instrument=False)

Supplying an explicit instrumentation list selects explicit mode and disables automatic discovery by default:

pip install respan-ai respan-instrumentation-openai-agents openai-agents
from respan import Respan
from respan_instrumentation_openai_agents import OpenAIAgentsInstrumentor

respan = Respan(
    instrumentations=[OpenAIAgentsInstrumentor()],
)

To deliberately combine an explicit plugin with direct-SDK automatic discovery:

respan = Respan(
    instrumentations=[OpenAIAgentsInstrumentor()],
    is_auto_instrument=True,
)

Explicit plugins activate first, so a matching automatic adapter is skipped rather than activated twice. Python currently provides a global automatic-discovery switch, but not a per-provider disable option.

Tracing Helpers

The facade re-exports Respan's tracing helpers:

from respan import agent, respan_span_attributes, task, tool, workflow

Use @workflow, @task, @agent, and @tool to structure traces, and use respan_span_attributes or propagate_attributes to attach customer, session, thread, environment, and metadata values.

Lifecycle

  • Respan() initializes telemetry and activates eligible adapters.
  • respan.flush() exports buffered spans without deactivating adapters.
  • respan.shutdown() deactivates adapters and flushes telemetry.

Examples

Public API

The package exports Respan, the automatic instrumentation registry and status types, OTELInstrumentor, the instrumentation protocol, tracing decorators, RespanClient, get_client, respan_span_attributes, and propagate_attributes.

License

Apache 2.0 — see the repository LICENSE.

Support

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

respan_ai-4.2.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

respan_ai-4.2.2-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file respan_ai-4.2.2.tar.gz.

File metadata

  • Download URL: respan_ai-4.2.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for respan_ai-4.2.2.tar.gz
Algorithm Hash digest
SHA256 dca27f19732b9442f9320825bec89831e6869044e4fb72ab044928b537f99579
MD5 5852e30a62b488435cd314c541872a3a
BLAKE2b-256 3c7ef66cdf7b7a3e3aa6b9b4a5bb1044d65c95ba0e4068e4a584c5ef1ee13f42

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_ai-4.2.2.tar.gz:

Publisher: publish.yml on respanai/respan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file respan_ai-4.2.2-py3-none-any.whl.

File metadata

  • Download URL: respan_ai-4.2.2-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for respan_ai-4.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 47d72ae615d6c554ba892d10d6d88a3593d0469c91ad7b939fd40de5a4326247
MD5 4079e2a694d788d62f60479705b683a9
BLAKE2b-256 2776c21aeeb91fde6083d3f73ef87d43404e5b90aa1d74ea457bc61e28bf16f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_ai-4.2.2-py3-none-any.whl:

Publisher: publish.yml on respanai/respan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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