Skip to main content

Python SDK for Pathlight — visual debugging and observability for AI agents

Project description

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 breakpointspl.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathlight-0.3.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathlight-0.3.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pathlight-0.3.3.tar.gz.

File metadata

  • Download URL: pathlight-0.3.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pathlight-0.3.3.tar.gz
Algorithm Hash digest
SHA256 d9efd41b3d18f2bcc7d035e1fbd17d56d356b1f898630998b8a37ccdb81fd375
MD5 d1ebbc7c5de6c95fe12a1eb32a1d0f6d
BLAKE2b-256 46ae1e13aed9945ffdf556887614b0bcbd9774a9470e7b80515e5e1c5fe3477f

See more details on using hashes here.

File details

Details for the file pathlight-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: pathlight-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pathlight-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ea2693cf49d0b841423df1595ca9bb9e147f620d7e69e53a748335d49d47df73
MD5 3f75b43f1ed0bd258ddc063a5dadc643
BLAKE2b-256 eef8c8e4fdae279c9e50fa48f05ed5963dace2de96fa370dd2c045c86bbba7ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page