trulayer. For narrative usage, see the tutorial. For configuration details, see configuration. For runnable end-to-end demos, see examples.
Source and issues
- Source: github.com/trulayer/client-python
- Issues / bug reports: github.com/trulayer/client-python/issues
- Package:
trulayeron PyPI
Module functions
trulayer.init()
Initialise the global client. Call once at app startup.
TruLayerClient. Stored as the process-wide global — retrievable via get_client().
trulayer.get_client()
RuntimeError if init() has not been called.
trulayer.trace()
Context manager that starts a new trace.
trulayer.atrace()
Async variant of trace(). Same signature; used with async with.
trulayer.current_trace()
None if no trace is active.
trulayer.shutdown()
Flush buffered spans and stop the background worker. Call on process exit.
Instrumentation helpers
trulayer.instrument_openai()
client.chat.completions.create and client.embeddings.create to emit spans automatically. Reversible via uninstrument_openai(client).
trulayer.instrument_anthropic()
client.messages.create to emit spans. Reversible via uninstrument_anthropic(client).
trulayer.instrument_langchain()
ChatModel, Chain, or Retriever via the callbacks=[...] argument.
Classes
TruLayerClient
Explicit client for multi-tenant apps or tests. Prefer init() + get_client() for single-client apps.
TraceContext
Returned by trace() and atrace(). Key methods:
SpanContext
Returned by TraceContext.span(). Key methods:
Models (Pydantic)
TraceData
SpanData
FeedbackData
EventData
Exceptions
The SDK never raises these to your call site — they’re logged and the trace is dropped. Subscribe via
trulayer.on_error(fn) if you need to handle them yourself.