Skip to main content

AI observability platform for LLM applications - Python SDK

Project description

Palantyra Python SDK

AI observability platform for LLM applications with automatic tracing.

Installation

pip install palantyra

For full functionality including async support and LLM client integrations:

pip install palantyra[full]

Quick Start

import palantyra

# Initialize once (like Laminar)
palantyra.initialize(api_key="your-api-key")

# All LLM calls are now automatically traced!
from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)
# ↑ This is automatically traced with cost, latency, tokens, etc.

Features

  • Zero-code tracing: Just initialize and go
  • Automatic cost tracking: Real-time cost calculation
  • Performance monitoring: Latency, token usage, error rates
  • Session correlation: Group related LLM calls
  • Multi-provider support: OpenAI, Anthropic, and more
  • Async support: Works with httpx, aiohttp
  • Framework integration: FastAPI, Django, Flask examples

Usage Examples

Manual Tracing

@palantyra.trace("My AI Function")
def process_text(text):
    palantyra.add_attribute("input_length", len(text))

    # Your LLM calls here
    result = client.chat.completions.create(...)

    palantyra.add_attribute("output_length", len(result))
    return result

Session Tracking

with palantyra.trace("Document Analysis"):
    palantyra.add_attribute("session_id", "session_123")

    # Multiple related LLM calls
    summary = summarize_document(doc)
    questions = generate_questions(doc)
    answers = answer_questions(questions, doc)

Error Handling

try:
    response = client.chat.completions.create(...)
except Exception as e:
    palantyra.set_error(e)
    raise

Direct Proxy Usage

You can also use Palantyra as a proxy without the SDK:

import requests

response = requests.post(
    "http://localhost:8080/proxy/openai/v1/chat/completions",
    headers={"Authorization": "Bearer your-palantyra-api-key"},
    json={"model": "gpt-4", "messages": [...]}
)

Configuration

palantyra.initialize(
    api_key="your-api-key",
    base_url="http://localhost:8080",  # Palantyra server
    project_id="my-project",
    timeout=30.0
)

Web Framework Integration

FastAPI

from fastapi import FastAPI
import palantyra

app = FastAPI()

@app.on_event("startup")
async def startup():
    palantyra.initialize(api_key="your-key")

@app.post("/chat")
async def chat(message: str):
    with palantyra.trace("Chat API"):
        # Your LLM logic here
        return {"response": "..."}

Django

# settings.py
MIDDLEWARE = [
    'myapp.middleware.PalantyraMiddleware',
    # ... other middleware
]

# middleware.py
import palantyra

class PalantyraMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response
        palantyra.initialize(api_key="your-key")

    def __call__(self, request):
        with palantyra.trace(f"{request.method} {request.path}"):
            return self.get_response(request)

Documentation

License

MIT License

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

Palantyra-1.0.6.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

Palantyra-1.0.6-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file Palantyra-1.0.6.tar.gz.

File metadata

  • Download URL: Palantyra-1.0.6.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for Palantyra-1.0.6.tar.gz
Algorithm Hash digest
SHA256 e0f089bb962552ace766f1657db567947d2186e8bd327a9b6faa467eb82a2c08
MD5 32aa236d8f1effc1d2c1de6457e95ef3
BLAKE2b-256 a9064de26173c7a2d58246642255f95e8d4c6bce9de621828a6ea42f63737e4b

See more details on using hashes here.

File details

Details for the file Palantyra-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: Palantyra-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for Palantyra-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fa4d06fbfe6b035114c309b641a92284e2ef2b06435ebda53b778179d3efac7d
MD5 41d0067c5c2a9a986beb5d06c1b115ac
BLAKE2b-256 4e69bc4f90027e5b0921f0ba266d89d6c2a44683fd0ab26e9b750dd85afb307d

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