FastAPI
bash
pip install "amlexia[fastapi]"python
from fastapi import FastAPI
from amlexia import AmlexiaClient
from amlexia.fastapi_integration import AmlexiaMiddleware
client = AmlexiaClient.from_env()
app = FastAPI()
app.add_middleware(AmlexiaMiddleware, client=client, service_name="api")
@app.get("/api/health")
async def health():
return {"status": "ok"}Lifespan shutdown
python
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
yield
client.shutdown()
app = FastAPI(lifespan=lifespan)