Skip to content

Glossary: Building APIs with FastAPI

Lifespan

Also written: lifespan function

A function FastAPI runs when the server starts and stops, with code before `yield` running at startup and code after it at shutdown. It is used for setup work such as creating database tables before the first request.

Where the book teaches it

Related terms

asynccontextmanager