FastAPI Events

Kludex

FastAPI Events

Today, we'll talk about the FastAPI events: "startup" and "shutdown".

The events are part of the [ASGI specification][asgi-specification], and they are called "lifespan" events.

Events

The "startup" event is triggered when the application starts.

Here's an example of a simple "startup" event:

```py from fastapi import FastAPI

app = FastAPI()

This post is for premium subscribers only.

Software Engineer @ Pydantic 🇧🇷🇺🇾🇮🇹 Uvicorn & Starlette maintainer 🦄🌟 FastAPI Expert ⚡

Better funding & community tools for developers

Learn more about our mission

Creator

Build, leverage & manage your own community using Subscriptions, Benefits & Posts

Become a Creator

Backer

Support your favorite open source projects by subscribing & receive exclusive benefits as a bonus

Become a Backer