diff --git a/fastapi/applications.py b/fastapi/applications.py index 05c7bd2be..348884dc5 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -512,6 +512,14 @@ class FastAPI(Starlette): Read more in the [FastAPI docs for `lifespan`](https://fastapi.tiangolo.com/advanced/events/). """ ), + deprecated( + """ + **Attention**: This parameter is deprecated. + + The recommended approach for managing startup and shutdown + is by utilizing the lifespan parameter within the FastAPI app. + """ + ), ] = None, on_shutdown: Annotated[ Optional[Sequence[Callable[[], Any]]], @@ -525,6 +533,14 @@ class FastAPI(Starlette): [FastAPI docs for `lifespan`](https://fastapi.tiangolo.com/advanced/events/). """ ), + deprecated( + """ + **Attention**: This parameter is deprecated. + + The recommended approach for managing startup and shutdown + is by utilizing the lifespan parameter within the FastAPI app. + """ + ), ] = None, lifespan: Annotated[ Optional[Lifespan[AppType]], diff --git a/fastapi/routing.py b/fastapi/routing.py index 54c75a027..dbd06cab9 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -764,6 +764,14 @@ class APIRouter(routing.Router): Read more in the [FastAPI docs for `lifespan`](https://fastapi.tiangolo.com/advanced/events/). """ ), + deprecated( + """ + **Attention**: This parameter is deprecated. + + The recommended approach for managing startup and shutdown + is by utilizing the lifespan parameter within the APIRouter. + """ + ), ] = None, on_shutdown: Annotated[ Optional[Sequence[Callable[[], Any]]], @@ -777,6 +785,14 @@ class APIRouter(routing.Router): [FastAPI docs for `lifespan`](https://fastapi.tiangolo.com/advanced/events/). """ ), + deprecated( + """ + **Attention**: This parameter is deprecated. + + The recommended approach for managing startup and shutdown + is by utilizing the lifespan parameter within the APIRouter. + """ + ), ] = None, # the generic to Lifespan[AppType] is the type of the top level application # which the router cannot know statically, so we use typing.Any