from contextlib import asynccontextmanager from fastapi import Depends, FastAPI from . import stats from .security import require_api_key @asynccontextmanager async def lifespan(app: FastAPI): # Nothing to set up — importing .security already loaded/generated the # API key, and stats.collect() is stateless — but FastAPI's lifespan is # the natural place a future migration/warmup step would go. yield app = FastAPI(title="VPS Dashboard Stats Agent", version="1.0.0", lifespan=lifespan) @app.get("/api/health") def health(): return {"status": "ok"} @app.get("/api/stats", dependencies=[Depends(require_api_key)]) def get_stats(): return stats.collect()