Skip to main content

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


Download files

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

Source Distribution

getstacklens-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

getstacklens-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file getstacklens-0.1.0.tar.gz.

File metadata

  • Download URL: getstacklens-0.1.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for getstacklens-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8121f0361dc4f430c94d72fdbaf250e73eb654480f1df325812aee79028ff386
MD5 75f8c2fbbdce2fbc136679c89d0e3693
BLAKE2b-256 8964f26184b2dec7375eb4df0259617aff121d2213300525a61383435c3e46d3

See more details on using hashes here.

File details

Details for the file getstacklens-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: getstacklens-0.1.0-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

Hashes for getstacklens-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 877a22497b1154cfb0c2029199a5da125856d2ff3e7efdb5f5ed082389c5033d
MD5 7e80ed3ba478941fc30117bd6eca8767
BLAKE2b-256 8254d2c1288b6ebd74024d45cdbd31b2dca6a8cd257461003b06b6342b0fd13e

See more details on using hashes here.

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