Edgenivo now supports lifespan events for FastAPI apps. This allows you to define logic that can execute on startup and graceful shutdown—such as managing database connections or flushing external logs.
from contextlib import asynccontextmanagerfrom fastapi import FastAPI
@asynccontextmanagerasync def lifespan(app: FastAPI): # Startup logic print("Starting up...") await startup_tasks() yield # Shutdown logic await cleanup_tasks()
app = FastAPI(lifespan=lifespan)Deploy FastAPI on Edgenivo or visit the FastAPI on Edgenivo documentation.