Langfuse just got faster →
← Back to changelog
July 4, 2024

Query Traces via SDKs

Picture Marc KlingenMarc Klingen
Query Traces via SDKs

The Langfuse Python and JS SDKs now support fetching traces and observations from the Langfuse API. Use them for custom analysis, few-shotting or fine-tuning workflows.

Since the very beginning, all Langfuse Tracing data has been open and accessible via the Langfuse API. Today, we're excited to finally release the SDK methods to conveniently query traces, observations, and sessions directly from the Langfuse API.

pip install langfuse
from langfuse import Langfuse
langfuse = Langfuse()

# Fetch list of traces, supports filters and pagination
traces = langfuse.fetch_traces()

# Fetch a single trace by ID
trace = langfuse.fetch_trace("traceId")

# Fetch list of observations, supports filters and pagination
observations = langfuse.fetch_observations()

# Fetch a single observation by ID
observation = langfuse.fetch_observation("observationId")

# Fetch list of sessions
sessions = langfuse.fetch_sessions()
npm install langfuse
import { Langfuse } from "langfuse";
const langfuse = new Langfuse();

// Fetch list of traces, supports filters and pagination
const traces = await langfuse.fetchTraces();

// Fetch a single trace by ID
const trace = await langfuse.fetchTrace("traceId");

// Fetch list of observations, supports filters and pagination
const observations = await langfuse.fetchObservations();

// Fetch a single observation by ID
const observation = await langfuse.fetchObservation("observationId");

// Fetch list of sessions
const sessions = await langfuse.fetchSessions();

See docs to learn more.


Was this page helpful?