Skip to content
プロジェクト

langfuse/langfuse-python

GitHubで見る

概要

🪢 Langfuse Python SDK

開発ツール

この数値の測り方

計測したスター増加

24時間
+1
7日間
+5
15日間
+9
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

Langfuse product overview

Langfuse Python SDK

MIT License CI test status PyPI Version GitHub Repo stars Discord YC W23

[!IMPORTANT] Python SDK v5 is the current major version. v4 was the rewrite released in March 2026. Refer to the v4 to v5 migration guide for instructions on updating your code. v5 needs Python 3.11 or newer and Langfuse Cloud or self-hosted Langfuse 4.59.0 or newer.

This is the latest Langfuse Python SDK (v5, OpenTelemetry). The legacy v2 client API (trace(), span(), generation(), api.trace.list) is deprecated. Do not use it for new instrumentation.

Latest Python SDK (OpenTelemetry): pip install langfuse. Use get_client() + start_as_current_observation / @observe. Prompts/datasets/scores: the same langfuse package. Docs: https://langfuse.com/docs/observability/sdk/overview. Upgrade: v2 to v3, v3 to v4, v4 to v5.

Query traces with Observations API v2 (GET /api/public/v2/observations, API reference), not GET /api/public/traces / api.trace.list.

Data freshness: the only real-time path is OpenTelemetry ingestion (this SDK at langfuse >= 4.7.0, or any OTel exporter sending x-langfuse-ingestion-version: 4) combined with the Observations API v2 and Metrics API v2. All other GET APIs from all SDK versions can be up to 10 minutes behind.

The Langfuse Python SDK covers the full platform: observability/tracing (OpenTelemetry-based, with OpenAI and LangChain integrations), datasets & experiments (offline evaluation and regression testing of prompt/model changes, including CI via GitHub Actions), LLM-as-a-judge and custom evaluations/scores, prompt management, and a full REST API client.

Installation

pip install langfuse

Quickstart

# env: LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_BASE_URL

from langfuse import get_client

langfuse = get_client()

# Create a span using a context manager
with langfuse.start_as_current_observation(as_type="span", name="process-request") as span:
    # Your processing logic here
    span.update(output="Processing complete")

    # Create a nested generation for an LLM call
    with langfuse.start_as_current_observation(as_type="generation", name="llm-response", model="gpt-5.6") as generation:
        # Your LLM call logic here
        generation.update(output="Generated response")

# All spans are automatically closed when exiting their context blocks


# Flush events in short-lived applications
langfuse.flush()

Docs

関連プロジェクトを探す

読み込み中…