You can register multiple handlers to events you want to run some code during the server startup or shutdown events.

Registering Handlers

Handlers can either be synchronous functions or async coroutines. For example, connecting to the database should be done on the on_startup event.

from yaat import Yaat

async def startup_task():

async def shutdown_task():

app = Yaat(

In Uvicorn, pass the argument lifespan to set the lifespan protocol.

uvicorn app:app --lifespan on

Read more here