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.
Metadata
Release files for zespan-fastapi 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zespan_fastapi-1.2.2.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zespan_fastapi-1.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.9 kB
Release files / zespan_fastapi-1.2.2.tar.gz
| Download URL | zespan_fastapi-1.2.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b81eea49bc301aaeb330ad9bfbc8d5783c448e17fef38229e4688abcba55964d
|
|
BLAKE2b-256 checksum How to use checksums |
de84393fd37b8a9f0fe0d1614f5237ec606d634a73f3571fb1b728739c6c0c22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / zespan_fastapi-1.2.2-py3-none-any.whl
| Download URL | zespan_fastapi-1.2.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62138b78b99fc6048b4d5c0e9be3f64b5418f1a1589dc299cb9cc2502ed67e24
|
|
BLAKE2b-256 checksum How to use checksums |
b78cc521ad4cee3c396dba55ed9c7be3142707aa60b8092a05d2838f8e5ce559
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|