from contextlib import asynccontextmanager from fastapi import FastAPI from poo import PooRecorder recorder = PooRecorder() @asynccontextmanager async def _lifespan(_app: FastAPI): await recorder.start() yield await recorder.stop() app = FastAPI(lifespan=_lifespan) @app.put("/record/s={status}") async def record(status: str) -> dict: return {"status": status}