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.3.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.3-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: respan_ai-4.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 d746235183421cfde8634a47f9741c752fd6a451fc8c2b5e006c6d996f3068da
MD5 1f1e44ff905fb0c7aa341ced5ddbb3de
BLAKE2b-256 49b75c362ec0c75743770dbaed7cb8d0e41d12d253d753ae5a5468f0b4bd8a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_ai-4.2.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: respan_ai-4.2.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 80d251944701be541b6d211556a381e911487c1b4b1e1388921783d0eee049ed
MD5 07a611996106d0f95a0531ae0430c89f
BLAKE2b-256 7fb5d38874921149403aa940d4c87aaf17f6c64ae315942d1cfde9ca8388bddc

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_ai-4.2.3-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