Skip to main content

pathlight — Python SDK

Python SDK for Pathlight — visual debugging, execution traces, and observability for AI agents.

Install

pip install pathlight

Usage

from pathlight import Pathlight

pl = Pathlight(base_url="http://localhost:4100")

with pl.trace("research-agent", input={"query": "What is WebAssembly?"}) as trace:
    with trace.span("classify", type="llm", model="gpt-4o") as s:
        result = openai.chat.completions.create(...)
        s.end(
            output=result.choices[0].message.content,
            input_tokens=result.usage.prompt_tokens,
            output_tokens=result.usage.completion_tokens,
            cost=0.003,
        )

    with trace.span("web-search", type="tool", tool_name="search") as t:
        docs = search_tool("WebAssembly")
        t.end(tool_result=docs)

    trace.end(output=final_answer)

Context-manager exits auto-close the trace/span. Raised exceptions mark the enclosing trace/span as failed with the exception message as the error.

Async

from pathlight import AsyncPathlight

async with AsyncPathlight(base_url="http://localhost:4100") as pl:
    trace = await pl.trace("agent")
    async with await trace.span("llm.chat", type="llm") as s:
        ...  # do work
        await s.end(input_tokens=50, output_tokens=10)
    await trace.end(output=result)

Features

All the dashboard features that the TypeScript SDK surfaces are available here too:

  • Auto git-context capture — commit, branch, dirty flag via git subprocess (cached once per process).
  • Auto source-location capture — stack-walk skips pathlight/ and stdlib frames, stores metadata._source so the dashboard shows file:line for every span.
  • Live breakpoints — pl.breakpoint(label=..., state=...) blocks until the dashboard resumes, returns the (possibly edited) state.
  • Fully typed with a py.typed marker.

Reference

Pathlight(...)

kwarg type purpose
base_url str Collector URL (required)
project_id str | None Group for multi-project installations
api_key str | None Bearer token sent as Authorization: Bearer …
disable_git_context bool Skip auto-detection of commit/branch
git GitContext | None Explicit override (wins over auto-detect)
timeout float httpx client timeout in seconds (default 10)

Trace.span(name, *, type="custom", ...)

Returns a Span. Types: "llm", "tool", "retrieval", "agent", "chain", "custom".

Span.end(*, output=None, input_tokens=None, output_tokens=None, cost=None, tool_result=None, ...)

Closes the span. All kwargs optional; use status="failed" + error=... for explicit failure.

pl.breakpoint(*, label, state=None, timeout_ms=None)

Registers a breakpoint and blocks until the dashboard resumes it. Returns whatever the dashboard posted back (the edited state); falls back to the original state on timeout or collector failure.

License

MIT

Metadata

Release files for pathlight 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pathlight 0.3.3
File Size Uploaded
pathlight-0.3.3.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pathlight 0.3.3
File Interpreter ABI Platform
pathlight-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / pathlight-0.3.3.tar.gz

Download URL pathlight-0.3.3.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d9efd41b3d18f2bcc7d035e1fbd17d56d356b1f898630998b8a37ccdb81fd375
BLAKE2b-256 checksum
How to use checksums
46ae1e13aed9945ffdf556887614b0bcbd9774a9470e7b80515e5e1c5fe3477f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / pathlight-0.3.3-py3-none-any.whl

Download URL pathlight-0.3.3-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea2693cf49d0b841423df1595ca9bb9e147f620d7e69e53a748335d49d47df73
BLAKE2b-256 checksum
How to use checksums
eef8c8e4fdae279c9e50fa48f05ed5963dace2de96fa370dd2c045c86bbba7ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page