You can register multiple handlers to events you want to run some code during the server startup or shutdown events.
Handlers can either be synchronous functions or async coroutines. For example, connecting to the database should be done on the
from yaat import Yaat async def startup_task(): ... async def shutdown_task(): ... app = Yaat( on_startup=[connect_database], on_shutdown=[email_stuffs] )
In Uvicorn, pass the argument
lifespanto set the lifespan protocol.
uvicorn app:app --lifespan on