diff --git a/docs/en/docs/tutorial/sql-databases.md b/docs/en/docs/tutorial/sql-databases.md
index b9f570dd5..58b55ea66 100644
--- a/docs/en/docs/tutorial/sql-databases.md
+++ b/docs/en/docs/tutorial/sql-databases.md
@@ -114,7 +114,7 @@ For production you would probably use a migration script that runs before you st
The `@app.on_event("startup")` and `@app.on_event("shutdown")` decorators are **deprecated** as of FastAPI v0.103.0.
-Use the `lifespan` parameter in the `FastAPI` class instead for lifecycle management.
+Use the `lifespan` parameter in the `FastAPI` class instead for lifecycle management.
///
diff --git a/docs_src/sql_databases/tutorial001.py b/docs_src/sql_databases/tutorial001.py
index 15d89e226..e99fb4ce5 100644
--- a/docs_src/sql_databases/tutorial001.py
+++ b/docs_src/sql_databases/tutorial001.py
@@ -28,16 +28,16 @@ def get_session():
yield session
-
-
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/")
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero:
session.add(hero)
diff --git a/docs_src/sql_databases/tutorial001_an.py b/docs_src/sql_databases/tutorial001_an.py
index 486a6db5f..1bd04e273 100644
--- a/docs_src/sql_databases/tutorial001_an.py
+++ b/docs_src/sql_databases/tutorial001_an.py
@@ -33,14 +33,15 @@ SessionDep = Annotated[Session, Depends(get_session)]
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/")
def create_hero(hero: Hero, session: SessionDep) -> Hero:
session.add(hero)
diff --git a/docs_src/sql_databases/tutorial001_an_py310.py b/docs_src/sql_databases/tutorial001_an_py310.py
index b1b483a35..7c71b312f 100644
--- a/docs_src/sql_databases/tutorial001_an_py310.py
+++ b/docs_src/sql_databases/tutorial001_an_py310.py
@@ -30,15 +30,18 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
+
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #This Allows app to run
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # This Allows app to run
+
+ # Statements below yield are ran after shutdown
- #Statements below yield are ran after shutdown
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/")
def create_hero(hero: Hero, session: SessionDep) -> Hero:
session.add(hero)
diff --git a/docs_src/sql_databases/tutorial001_an_py39.py b/docs_src/sql_databases/tutorial001_an_py39.py
index dd7e7c3e3..adac52409 100644
--- a/docs_src/sql_databases/tutorial001_an_py39.py
+++ b/docs_src/sql_databases/tutorial001_an_py39.py
@@ -31,15 +31,16 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
-
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/")
def create_hero(hero: Hero, session: SessionDep) -> Hero:
session.add(hero)
diff --git a/docs_src/sql_databases/tutorial001_py310.py b/docs_src/sql_databases/tutorial001_py310.py
index 91eb5956f..b000b4956 100644
--- a/docs_src/sql_databases/tutorial001_py310.py
+++ b/docs_src/sql_databases/tutorial001_py310.py
@@ -27,15 +27,16 @@ def get_session():
yield session
-
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/")
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero:
session.add(hero)
diff --git a/docs_src/sql_databases/tutorial001_py39.py b/docs_src/sql_databases/tutorial001_py39.py
index 978f90e74..12c9e0169 100644
--- a/docs_src/sql_databases/tutorial001_py39.py
+++ b/docs_src/sql_databases/tutorial001_py39.py
@@ -28,15 +28,16 @@ def get_session():
yield session
-
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/")
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero:
session.add(hero)
diff --git a/docs_src/sql_databases/tutorial002.py b/docs_src/sql_databases/tutorial002.py
index f17dfdc09..0fb007117 100644
--- a/docs_src/sql_databases/tutorial002.py
+++ b/docs_src/sql_databases/tutorial002.py
@@ -45,17 +45,16 @@ def get_session():
yield session
-
-
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #StartUp
- yield #Allows app to run
- #Shut down
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # StartUp
+ yield # Allows app to run
+ # Shut down
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)):
db_hero = Hero.model_validate(hero)
diff --git a/docs_src/sql_databases/tutorial002_an.py b/docs_src/sql_databases/tutorial002_an.py
index b5dd22acf..fa1970dad 100644
--- a/docs_src/sql_databases/tutorial002_an.py
+++ b/docs_src/sql_databases/tutorial002_an.py
@@ -50,13 +50,15 @@ SessionDep = Annotated[Session, Depends(get_session)]
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: SessionDep):
db_hero = Hero.model_validate(hero)
diff --git a/docs_src/sql_databases/tutorial002_an_py310.py b/docs_src/sql_databases/tutorial002_an_py310.py
index 3989b5082..db074cd92 100644
--- a/docs_src/sql_databases/tutorial002_an_py310.py
+++ b/docs_src/sql_databases/tutorial002_an_py310.py
@@ -49,13 +49,15 @@ SessionDep = Annotated[Session, Depends(get_session)]
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: SessionDep):
db_hero = Hero.model_validate(hero)
diff --git a/docs_src/sql_databases/tutorial002_an_py39.py b/docs_src/sql_databases/tutorial002_an_py39.py
index 8b45dd9db..e87a7db12 100644
--- a/docs_src/sql_databases/tutorial002_an_py39.py
+++ b/docs_src/sql_databases/tutorial002_an_py39.py
@@ -49,13 +49,15 @@ SessionDep = Annotated[Session, Depends(get_session)]
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: SessionDep):
db_hero = Hero.model_validate(hero)
diff --git a/docs_src/sql_databases/tutorial002_py310.py b/docs_src/sql_databases/tutorial002_py310.py
index c71bd19e0..07a2a2399 100644
--- a/docs_src/sql_databases/tutorial002_py310.py
+++ b/docs_src/sql_databases/tutorial002_py310.py
@@ -44,16 +44,16 @@ def get_session():
yield session
-
-
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)):
db_hero = Hero.model_validate(hero)
diff --git a/docs_src/sql_databases/tutorial002_py39.py b/docs_src/sql_databases/tutorial002_py39.py
index 412bdb410..09c78b097 100644
--- a/docs_src/sql_databases/tutorial002_py39.py
+++ b/docs_src/sql_databases/tutorial002_py39.py
@@ -45,15 +45,16 @@ def get_session():
yield session
-
@asynccontextmanager
-async def lifespan(app:FastAPI):
- create_db_and_tables() #Startup
- yield #Allows app to run
- #Shutdown
+async def lifespan(app: FastAPI):
+ create_db_and_tables() # Startup
+ yield # Allows app to run
+ # Shutdown
+
app = FastAPI(lifespan=lifespan)
+
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)):
db_hero = Hero.model_validate(hero)