Skip to main content
The Python SDK (trulayer on PyPI) is the primary way to send traces to TruLayer from Python code. It supports manual tracing, auto-instrumentation of popular LLM clients, and async/sync usage patterns.

Install

pip install trulayer
Python 3.11+ required.

Minimal usage

import os
import trulayer

trulayer.init(
    api_key=os.environ["TRULAYER_API_KEY"],
    project="my-app",
)

with trulayer.trace("do_work") as trace:
    trace.set_input({"prompt": "hello"})
    # ... your code ...
    trace.set_output({"response": "world"})

What’s included

ImportPurpose
trulayer.init(...)Initialise the global client
trulayer.trace(name)Context manager for a trace
trulayer.atrace(name)Async variant
trulayer.current_trace()Get the active trace from async-local context
trulayer.instrument_openai(client)Auto-patch an OpenAI client
trulayer.instrument_anthropic(client)Auto-patch an Anthropic client
trulayer.instrument_langchain()Register a LangChain callback handler
trulayer.TruLayerClientClass for explicit multi-instance use
trulayer.TraceData, SpanData, EventData, FeedbackDataPydantic models
Full signatures: Reference.

Where to go next

Tutorial

Step-by-step: manual tracing → auto-instrumentation → async → feedback → production.

Configuration

Batch size, flush interval, sampling, PII scrubbing, debug mode.

Reference

Every public export, with signatures and examples.

Concepts

Understand the data model before going deep.