Python SDK for GetStackLens — observability and governance for your AI stack
Project description
GetStackLens Python SDK
Python SDK for GetStackLens — observability and governance for your AI stack.
Trace LLM calls, fetch versioned prompts, and enforce AI governance policies — in three lines of Python.
Installation
pip install getstacklens
Requires Python 3.9+.
Quickstart
import getstacklens
getstacklens.configure(api_key="sl-xxxx")
getstacklens.trace("my-llm-call", model="gpt-4o", provider="openai", input_tokens=150, output_tokens=200)
Get your API key from the GetStackLens dashboard under Settings → API Keys.
Tracing LLM calls
Simple trace (one line)
For accurate latency, record start_time before the call and pass it in:
from datetime import datetime, timezone
import getstacklens
getstacklens.configure(api_key="sl-xxxx")
start = datetime.now(timezone.utc)
response = openai_client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Summarise this document."}],
)
getstacklens.trace(
"chat-completion",
model="gpt-4o",
provider="openai",
input_tokens=response.usage.prompt_tokens,
output_tokens=response.usage.completion_tokens,
start_time=start,
)
Context manager (recommended for agent workflows)
import openai
import getstacklens
getstacklens.configure(api_key="sl-xxxx")
client = openai.OpenAI()
with getstacklens.start_trace("customer-support-agent") as span:
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "How do I reset my password?"}],
)
span.record_llm(
model="gpt-4o",
provider="openai",
input_tokens=response.usage.prompt_tokens,
output_tokens=response.usage.completion_tokens,
completion=response.choices[0].message.content,
)
span.set_attribute("user_id", "u_123")
span.add_tag("support", "production")
If an exception is raised inside the context, the span status is automatically set to error.
Fetching versioned prompts (FlowOps)
Manage prompts in the GetStackLens dashboard, then fetch them at runtime — no deploys needed.
import getstacklens
getstacklens.configure(api_key="sl-xxxx")
# Fetch the active prompt for the production environment
system_prompt = getstacklens.prompts.get("support-system-prompt", env="production")
# Use in an LLM call
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_message},
],
)
Available environments: "dev", "staging", "production" (default).
Self-hosted deployments
Point the SDK at your own GetStackLens instance:
getstacklens.configure(
api_key="sl-xxxx",
endpoint="https://api.your-domain.com",
)
See the self-hosting guide for setup instructions.
Supported providers
Works with any LLM provider — pass the model and provider name you use:
| Provider | provider value |
|---|---|
| OpenAI | "openai" |
| Anthropic | "anthropic" |
| Google Gemini | "gemini" |
| Azure OpenAI | "azure-openai" |
| AWS Bedrock | "bedrock" |
| Any other | any string |
Links
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
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 getstacklens-0.1.1.tar.gz.
File metadata
- Download URL: getstacklens-0.1.1.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb1aaee84a30e2442ecda514a115ffd315167e8b0ade5cdd4d44014159c5351
|
|
| MD5 |
89ad028b6b523dc281bbf05bb7258ff9
|
|
| BLAKE2b-256 |
79d783feaf905fd62628e8009583fa4285f16020b69061c4a9f2d36c228df5e3
|
File details
Details for the file getstacklens-0.1.1-py3-none-any.whl.
File metadata
- Download URL: getstacklens-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2c688f2101187b1ec0596583ca9391781dc83aa51e588be3d53d5d62e987436
|
|
| MD5 |
b7787faa0a9c810317e96f8797007a19
|
|
| BLAKE2b-256 |
414727b30d0b5cf3280315119c8445f8c0295add77dd6ed5e3e75b3f5e035ab2
|