P
SDK
Python SDK
The official Lanternfish Python SDK. Records your agent's LLM calls, steps and decisions, and sends each run to Lanternfish.
1
Install the SDK
bash
pip install lanternfishRequires Python 3.11 or higher
2
Initialize the client
python
import lanternfish
import os
# Initialize Lanternfish directly
lanternfish.instrument(
api_key=os.environ["LANTERNFISH_API_KEY"],
endpoint=os.environ["LANTERNFISH_ENDPOINT"],
)3
Send your first trace
python
from lanternfish import trace, span
from lanternfish.semantic import planning, reasoning
# 1. Track custom steps automatically using @trace
@trace
def run_agent_workflow(user_query):
# Parameters like user_query are automatically captured
# 2. Use planning and reasoning context managers
with planning() as p:
p.select_tool("FlightSearch", reason="User is asking for flights")
with reasoning() as r:
r.add_context(user_query)
r.decide("FlightSearch", confidence=0.95)
# 3. Custom spans with metadata attributes
with span("execute_booking") as s:
s.set_attribute("booking.destination", "London")
return "Booking confirmed"What Lanternfish captures
- Complete trace timeline
- Token usage and cost
- Latency metrics
- Tool and function calls
- Error tracking
- Model information