Langfuse `TraceSource` adapter for whatifd.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whatifd_langfuse-0.2.0.tar.gz.
File metadata
- Download URL: whatifd_langfuse-0.2.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
042d696cbc458aa9b7d8ad99227a5200b82a063b3ac2ce61153639d86ee55ca0
|
|
| MD5 |
39dc978c0f7c70d5cecd46d0c779142e
|
|
| BLAKE2b-256 |
befe072b8694cc872f2fcc343d1d53e0175d2ede55f7d5f8260ed65c61a34cac
|
Provenance
The following attestation bundles were made for whatifd_langfuse-0.2.0.tar.gz:
Publisher:
release.yml on victoralfred/whatifd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
whatifd_langfuse-0.2.0.tar.gz -
Subject digest:
042d696cbc458aa9b7d8ad99227a5200b82a063b3ac2ce61153639d86ee55ca0 - Sigstore transparency entry: 1498132389
- Sigstore integration time:
-
Permalink:
victoralfred/whatifd@9cadf0c5cacdb8826311364713746099b68aff3a -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/victoralfred
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9cadf0c5cacdb8826311364713746099b68aff3a -
Trigger Event:
push
-
Statement type:
File details
Details for the file whatifd_langfuse-0.2.0-py3-none-any.whl.
File metadata
- Download URL: whatifd_langfuse-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d86afaf7ba6df1d459bb8f6a518bc21d291737c7568a7daee8dd942470ab4d1b
|
|
| MD5 |
978279fe6f0a24f9b56cf0bbf5fc6e15
|
|
| BLAKE2b-256 |
fe6afd036e65e3218ed392cc0731f7ed7751e7247c4f1af038e00823cb407f24
|
Provenance
The following attestation bundles were made for whatifd_langfuse-0.2.0-py3-none-any.whl:
Publisher:
release.yml on victoralfred/whatifd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
whatifd_langfuse-0.2.0-py3-none-any.whl -
Subject digest:
d86afaf7ba6df1d459bb8f6a518bc21d291737c7568a7daee8dd942470ab4d1b - Sigstore transparency entry: 1498132596
- Sigstore integration time:
-
Permalink:
victoralfred/whatifd@9cadf0c5cacdb8826311364713746099b68aff3a -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/victoralfred
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9cadf0c5cacdb8826311364713746099b68aff3a -
Trigger Event:
push
-
Statement type: