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.0.tar.gz (9.3 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.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathlight-0.3.0.tar.gz
  • Upload date:
  • Size: 9.3 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.0.tar.gz
Algorithm Hash digest
SHA256 4a63fdfb9b163fa87c351f9571dc5177d6c880f8a3d7435da79452e4fe8138dd
MD5 5ee3cbe6abea68425c7dd03d390636fa
BLAKE2b-256 249bb3d9e96609570b0ece6bdf3b8872413a3012525cc716a2321c8fd8c2afa3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pathlight-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a37c27bf181b25163824bd226db8bc65ab0aa92b514e4b0f74fe1b3927e68a43
MD5 d026fc67adf2e5ae75100ade88704a3c
BLAKE2b-256 8bd7340704d9607fde7ffe950b6a96c3470d203f7c21c5399d96ef6d757204c6

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