Zespan observability middleware for FastAPI
Project description
zespan-fastapi
Automatic LLM observability middleware for FastAPI. Traces every request, LLM call, and custom span with zero code changes for basic usage.
Installation
pip install zespan-fastapi
Quick Start
from fastapi import FastAPI
from zespan_fastapi import ZespanFastAPIMiddleware, ZespanConfig
app = FastAPI()
config = ZespanConfig(api_key="zsp_your_api_key")
app.add_middleware(ZespanFastAPIMiddleware, config=config)
Every HTTP request is now automatically traced.
Trace LLM Calls
from zespan_fastapi import observe_llm
@observe_llm(model="gpt-4o", provider="openai")
async def generate_response(prompt: str):
response = await openai.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
return response
Trace Custom Spans
from zespan_fastapi import observe_span
@observe_span("fetch_context", span_type="retrieval")
async def fetch_context(query: str):
return await vector_db.search(query)
Set Custom Attributes
from zespan_fastapi import set_attribute
@app.post("/chat")
async def chat(request: ChatRequest):
set_attribute("user.id", request.user_id)
set_attribute("model", request.model)
Configuration
| Option | Default | Description |
|---|---|---|
api_key |
required | Zespan API key (zsp_...) |
base_url |
https://api.zespan.com |
API endpoint |
enabled |
True |
Toggle tracing on/off |
sample_rate |
1.0 |
Fraction of requests to trace (0.0–1.0) |
capture_request_body |
False |
Include request body in traces |
capture_response_body |
False |
Include response body in traces |
redact_fields |
["password","token","api_key"] |
Fields redacted automatically |
debug |
False |
Print flush errors to stdout |
Get your API key at zespan.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zespan_fastapi-1.0.0.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zespan_fastapi-1.0.0.tar.gz.
File metadata
- Download URL: zespan_fastapi-1.0.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"AMD64","implementation":{"name":"CPython","version":"3.14.2"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.0.18 30 Sep 2025","python":"3.14.2","system":{"name":"Windows","release":"11"}} HTTPX2/2.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07c4f1295db704e4b20496b1ff79b0618c65f693a002ef5dbf21700ba67fad8b
|
|
| MD5 |
7878251c148994d351cab050e5cebac8
|
|
| BLAKE2b-256 |
a189c5730ae795cd8e7d3579ee908db19c3d9bf3aab7d1c4a4dedc1297d58bf6
|
File details
Details for the file zespan_fastapi-1.0.0-py3-none-any.whl.
File metadata
- Download URL: zespan_fastapi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"AMD64","implementation":{"name":"CPython","version":"3.14.2"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.0.18 30 Sep 2025","python":"3.14.2","system":{"name":"Windows","release":"11"}} HTTPX2/2.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4a53259ec2943d5d1ffbafa31bbdad0c80c50267ebb5f9217cd6cd639390a0c
|
|
| MD5 |
f12173da76c49e58668f47bfa8d766f5
|
|
| BLAKE2b-256 |
5fa3a2ce8edf42b77f82afcbb5920dcc3147ab8562b0661fc0c8fa5fda9c53a0
|