Skip to main content

Lightweight LLM tracing SDK with remote tool invocation

Project description

lightrace-python

Lightweight LLM tracing SDK for Python with remote tool invocation.

Install

pip install lightrace

Quick Start

from lightrace import Lightrace, trace

lt = Lightrace(
    public_key="pk-lt-demo",
    secret_key="sk-lt-demo",
    host="http://localhost:3002",
)

# Root trace
@trace()
def run_agent(query: str):
    return search(query)

# Span
@trace(type="span")
def search(query: str) -> list:
    return ["result1", "result2"]

# Generation (LLM call)
@trace(type="generation", model="gpt-4o")
def generate(prompt: str) -> str:
    return "LLM response"

# Tool — remotely invocable from the Lightrace UI
@trace(type="tool")
def weather_lookup(city: str) -> dict:
    return {"temp": 72, "unit": "F"}

# Tool — traced but NOT remotely invocable
@trace(type="tool", invoke=False)
def read_file(path: str) -> str:
    return open(path).read()

run_agent("hello")
lt.flush()
lt.shutdown()

@trace API

@trace()                                    # Root trace
@trace(type="span")                         # Span observation
@trace(type="generation", model="gpt-4o")   # LLM generation
@trace(type="tool")                         # Tool (remotely invocable)
@trace(type="tool", invoke=False)           # Tool (trace only)

Parameters

Parameter Type Default Description
type str None "span", "generation", "tool", "chain", "event"
name str None Override name (defaults to function name)
invoke bool True For type="tool": register for remote invocation
model str None For type="generation": LLM model name
metadata dict None Static metadata attached to every call

Compatibility

Lightrace server also accepts traces from Langfuse Python/JS SDKs.

Development

uv sync --extra dev
uv run pre-commit install
uv run pytest -s -v tests/
uv run ruff check .
uv run mypy src/lightrace

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

lightrace-0.1.1.tar.gz (113.2 kB view details)

Uploaded Source

Built Distribution

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

lightrace-0.1.1-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file lightrace-0.1.1.tar.gz.

File metadata

  • Download URL: lightrace-0.1.1.tar.gz
  • Upload date:
  • Size: 113.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lightrace-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b075a02f6ed85b3a448d2cdc392ddc5e478a82da2d5b43f34bef4321f0ff03e
MD5 d6d9edcf5ed50907607e64bbb58845ae
BLAKE2b-256 e0ebb0c17ee552a3f27f797b6490339e02ffcc3fad6d26ad4c9a08a8e11fd8cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for lightrace-0.1.1.tar.gz:

Publisher: release.yml on SKE-Labs/lightrace-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lightrace-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lightrace-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lightrace-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5b69b48446a701d093ac95350052f13d9b27b21edb14b3c8103c1921cf09b09
MD5 5ba6a34218c8228baa01fc32336ca6e1
BLAKE2b-256 f2ed97398f7dc9e55ebe995f9d7502ab9fb1d8913fa9b511495f2e0f090a58d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for lightrace-0.1.1-py3-none-any.whl:

Publisher: release.yml on SKE-Labs/lightrace-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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