Skip to main content

LLM observability SDK for Python

Project description

Untrace SDK for Python

LLM observability SDK for Python applications.

Installation

pip install untrace-sdk

Quick Start

import asyncio
from untrace import UntraceClient

async def main():
    # Initialize the client
    async with UntraceClient(api_key="your-api-key") as client:
        # Send a trace event
        trace = await client.trace(
            event_type="llm_call",
            data={
                "model": "gpt-4",
                "prompt": "Hello, world!",
                "response": "Hello! How can I help you today?",
                "tokens_used": 25,
            },
            metadata={
                "user_id": "user123",
                "session_id": "session456",
            }
        )

        print(f"Trace created: {trace.id}")

# Run the async function
asyncio.run(main())

Synchronous Usage

from untrace import UntraceClient

# Initialize the client
client = UntraceClient(api_key="your-api-key")

# Send a trace event
trace = client.trace_sync(
    event_type="llm_call",
    data={
        "model": "gpt-4",
        "prompt": "Hello, world!",
        "response": "Hello! How can I help you today?",
    }
)

print(f"Trace created: {trace.id}")

# Don't forget to close the client
client.close()

API Reference

UntraceClient

The main client class for interacting with the Untrace API.

Constructor

UntraceClient(
    api_key: str,
    base_url: str = "https://api.untrace.dev",
    timeout: float = 30.0,
)

Methods

  • trace(event_type, data, metadata=None): Send a trace event (async)
  • trace_sync(event_type, data, metadata=None): Send a trace event (sync)
  • get_trace(trace_id): Retrieve a trace by ID (async)
  • close(): Close the HTTP client

Error Handling

The SDK provides specific exception types for different error scenarios:

  • UntraceError: Base exception for all SDK errors
  • UntraceAPIError: Raised when API requests fail
  • UntraceValidationError: Raised when request validation fails
from untrace import UntraceClient, UntraceAPIError, UntraceValidationError

try:
    client = UntraceClient(api_key="your-api-key")
    trace = client.trace_sync("llm_call", {"model": "gpt-4"})
except UntraceValidationError as e:
    print(f"Validation error: {e}")
except UntraceAPIError as e:
    print(f"API error: {e}")

Development

Setup

# Clone the repository
git clone https://github.com/untrace-dev/untrace-sdk.git
cd untrace-sdk/sdks/python

# Install in development mode
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black src/
isort src/
ruff check src/

License

MIT License - see LICENSE file for details.

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

untrace_sdk-0.1.0.tar.gz (94.4 kB view details)

Uploaded Source

Built Distribution

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

untrace_sdk-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: untrace_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 94.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for untrace_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ca0404f3a04f1f102bf6eb30e50eb4efc817742f5e285b481489bd44023494b7
MD5 add27b6b192d6d37ba90612f459e6383
BLAKE2b-256 c611bbd999dcd212eebacd4906ea2be5f329e36a37c43e6865ca822342d773ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: untrace_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for untrace_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d332e1d1d1c5a38028cb7a6d810ba133723953b04af27388af4c5c8813837cff
MD5 d22c70be3ae3bb1cef8a079ede943293
BLAKE2b-256 3ed1b208f2ba27627dd71a5e5d435e2402281d9f94a878840ce6347c67e5aa7f

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