Integration with the Observ AI platform for Python projects.
Project description
Observ Python SDK
AI tracing and semantic caching SDK for Observ.
Installation
pip install observ-sdk
Install provider-specific SDKs as needed:
# For Anthropic
pip install observ-sdk[anthropic]
# For OpenAI (also used by xAI and OpenRouter)
pip install observ-sdk[openai]
# For Google Gemini
pip install observ-sdk[gemini]
# For Mistral
pip install observ-sdk[mistral]
# Install all providers
pip install observ-sdk[all]
Quick Start
Anthropic
import anthropic
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True, # Enable semantic caching
)
client = anthropic.Anthropic(api_key="your-anthropic-key")
client = ob.anthropic(client)
# Use normally - all calls are automatically traced
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content[0].text)
OpenAI
import openai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = openai.OpenAI(api_key="your-openai-key")
client = ob.openai(client)
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Google Gemini
import google.generativeai as genai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
genai.configure(api_key="your-gemini-key")
model = genai.GenerativeModel("gemini-pro")
model = ob.gemini(model)
response = model.generate_content("Hello!")
print(response.text)
Mistral
from mistralai import Mistral
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = Mistral(api_key="your-mistral-key")
client = ob.mistral(client)
response = client.chat.completions.create(
model="mistral-large-latest",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
xAI (Grok)
import openai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = openai.OpenAI(
api_key="your-xai-key",
base_url="https://api.x.ai/v1"
)
client = ob.xai(client)
response = client.chat.completions.create(
model="grok-beta",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
OpenRouter
import openai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = openai.OpenAI(
api_key="your-openrouter-key",
base_url="https://openrouter.ai/api/v1"
)
client = ob.openrouter(client)
response = client.chat.completions.create(
model="openai/gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Configuration
ob = Observ(
api_key="your-observ-api-key", # Required
recall=True, # Enable semantic caching (default: False)
environment="production", # Environment tag (default: "production")
endpoint="https://api.observ.dev", # Custom endpoint (optional)
debug=False, # Enable debug logging (default: False)
)
Features
- Automatic Tracing: All LLM calls are automatically traced
- Semantic Caching: Cache similar prompts to reduce costs and latency
- Multi-Provider: Support for Anthropic, OpenAI, Gemini, Mistral, xAI, and OpenRouter
- Session Tracking: Group related calls with session IDs
- Metadata: Attach custom metadata to traces
Metadata and Sessions
All wrapped clients support metadata and session ID chaining:
# Add metadata to a request
response = client.messages.with_metadata({"user_id": "123", "feature": "chat"}).create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello!"}]
)
# Track conversation sessions
response = client.messages.with_session_id("conversation-abc").create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello!"}]
)
# Combine both
response = client.messages.with_metadata({"user_id": "123"}).with_session_id("session-abc").create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello!"}]
)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
observ_sdk-0.1.1.tar.gz
(10.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file observ_sdk-0.1.1.tar.gz.
File metadata
- Download URL: observ_sdk-0.1.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42186660f667d264a0d79621779ee3cf3d1c20d8884f767d223f2d8210a0e1ac
|
|
| MD5 |
08e068bc7d739ceef0e02ebb535d193e
|
|
| BLAKE2b-256 |
53e797ca017cac4c693e92338f1f560598f6b8d60f62a634425490559b407b84
|
File details
Details for the file observ_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: observ_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc08989681e20c0a157eeab0d4fa50bd6de401c9dbe3ab9bd50a81d93c1b556f
|
|
| MD5 |
3686feca3d906ba8523f8b06d274839d
|
|
| BLAKE2b-256 |
2ac1bf0214befde529ca00372d327781f71860396c7c2713031a94dccac5c28e
|