whatifd-langfuse
Langfuse TraceSource adapter for whatifd. Phase 4B.1 of the v0.1 plan.
Install
pip install whatifd-langfuse
Pulls whatifd and langfuse>=4.5.1,<5.0 (industry-standard library pinning: lower bound + major-version cap).
Usage
import os
from langfuse.api import LangfuseAPI
from whatifd_langfuse import LangfuseTraceSource
api = LangfuseAPI(
base_url=os.environ["LANGFUSE_HOST"],
username=os.environ["LANGFUSE_PUBLIC_KEY"],
password=os.environ["LANGFUSE_SECRET_KEY"],
)
source = LangfuseTraceSource(
api=api,
cohort_classifier=lambda trace: "failure" if "failed" in (trace.tags or []) else "baseline",
page_limit=50,
max_traces=200, # cap iteration so a fixture run can't drain a production project
)
for raw in source.iter_traces():
print(raw.trace_id, raw.cohort)
Cardinal alignment
- #5 Sensitive at the boundary: every text field that carries user content (
user_message,original_response) is wrapped at construction. Traceinput/outputmay be string, dict, or list per Langfuse's typed-Any field; the adapter projects to a canonical JSON string (sort_keys=True for determinism) and wraps. - #9 orchestration, not compute: streaming pagination is I/O-bound;
iter_tracesis a generator, never a list build-up. - #10 statistical claims:
cluster_key_support()returns an emptyavailable_keystuple. Surfacing Langfuseuser_id/session_idas cluster keys is an inferential commitment that v0.1 does NOT make; v0.2+ may add explicit per-field opt-in.
Testing
The package ships two test surfaces:
-
Mocked-client conformance (
tests/test_conformance.py) — runs the parent repo'sTraceSourceConformanceharness against an in-file fakeLangfuseAPI. No network. CI runs this on every change. -
Recorded real-network smoke (
tests/test_recorded_smoke.py) — runs against a real Langfuse instance using credentials in environment variables. The first run records HTTP cassettes viapytest-recording; subsequent runs replay from the cassette. CI replays from the committed cassette; recording is a local dev step.
Recording cassettes (one-time, by a contributor with credentials)
LANGFUSE_HOST=https://cloud.langfuse.com \
LANGFUSE_PUBLIC_KEY=pk-... \
LANGFUSE_SECRET_KEY=sk-... \
uv run pytest packages/whatifd-langfuse/tests/test_recorded_smoke.py --record-mode=once
The cassette is committed under tests/cassettes/. Sensitive headers (Authorization, x-langfuse-public-key) are filtered out by the vcr_config fixture.
Contributor setup
This package lives in the parent whatifd monorepo as a uv workspace member. From the repo root:
uv sync --all-extras --dev --group workspace
The --group workspace flag pulls the in-tree whatifd-langfuse editable install via PEP 735 dependency groups (uv-native). Without it, uv sync --all-extras --dev installs the rest of the dev environment but leaves this package out, and pytest packages/whatifd-langfuse/tests/ fails with ModuleNotFoundError: whatifd_langfuse.
Plain pip install ".[dev]" will NOT work for the workspace package — pip ignores PEP 735 groups (that's deliberate; the workspace dep can't be resolved from PyPI because it isn't published yet). Use uv for development setup; pip-only consumers install the published whatifd-langfuse from PyPI once it lands.
Stability
Pre-1.0; the adapter follows whatifd's v0.1 stability contract. The Langfuse SDK upper-cap (<5.0) reserves the next major for a coordinated migration if Langfuse changes the LangfuseAPI.trace.list(...) shape.
Metadata
Release files for whatifd-langfuse 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| whatifd_langfuse-0.3.0.tar.gz | 19.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| whatifd_langfuse-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.9 kB
Release files / whatifd_langfuse-0.3.0.tar.gz
| Download URL | whatifd_langfuse-0.3.0.tar.gz |
|---|---|
| Size | 19.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
152abacde71e8abff3c4cb62a1a2a0a99638abaa1ce441aa495950b6834d6385
|
|
BLAKE2b-256 checksum How to use checksums |
eb3fda0dd2883af4710d123425851bcb6633d3fff785c27802493737aa382632
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.
Transparency logRelease files / whatifd_langfuse-0.3.0-py3-none-any.whl
| Download URL | whatifd_langfuse-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
90cb79676755df5b6f8ddef587b35b32dac6053bcba94e805db2d98e0df4e5b9
|
|
BLAKE2b-256 checksum How to use checksums |
26fb8f113b6f80af466a32eeedeadd7cc5decbceeab057499b72e6d8d6da6915
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.
Transparency log