SDKs
Python SDK Guide
Server-side Python SDK (Python 3.10+) with standard library transport, FastAPI exception handlers, and Celery job capture.
The Lazers Python SDK (`lazers`) requires Python 3.10+ and uses only the Python standard library with zero third-party dependencies.
Installation ```bash pip install lazers ```
Initialization Create the client once during application startup and reuse it across requests:
Integration Code Examples
FastAPI Integration
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from lazers import LazersClient
lazers = LazersClient(
api_key=os.environ["LAZERS_API_KEY"],
endpoint=os.getenv("LAZERS_ENDPOINT", "https://api.lazers.app"),
project_id=os.environ["LAZERS_PROJECT_ID"],
environment=os.getenv("LAZERS_ENVIRONMENT", "production"),
service_name="orders-service",
release=os.getenv("GIT_COMMIT_SHA"),
)
@asynccontextmanager
async def lifespan(app: FastAPI):
yield
# Flush pending telemetry during graceful shutdown
lazers.flush()
app = FastAPI(lifespan=lifespan)
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
lazers.capture_error(
exc,
correlation_id=request.headers.get("x-request-id"),
actor={"type": "customer", "id": getattr(request.state, "user_id", "anonymous")}
)
raise excCelery / Background Tasks
from celery import Celery
from lazers import LazersClient
app = Celery("tasks")
lazers = LazersClient(...)
@app.task(bind=True)
def process_invoice(self, invoice_id: str):
try:
generate_pdf(invoice_id)
except Exception as error:
lazers.capture_error(
error,
correlation_id=invoice_id,
metadata={"task_name": self.name, "task_id": self.request.id}
)
raise