Dependencies API
The dependencies module contains the underlying logic for handling deprecation lifecycles. It allows for more advanced usage patterns, such as applying deprecation to entire routers or registering global callbacks.
Router Deprecation
You can deprecate an entire APIRouter by adding DeprecationDependency to its dependencies list.
from fastapi import APIRouter, Depends
from fastapi_deprecation import DeprecationDependency
router = APIRouter(
dependencies=[
Depends(DeprecationDependency(deprecation_date="2024-06-01"))
]
)
fastapi_deprecation.dependencies
DeprecationDependency
A dependency that can be used to deprecate an endpoint or router.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deprecation_date
|
Optional[DateInput]
|
The date when the endpoint is deprecated. |
None
|
sunset_date
|
Optional[DateInput]
|
The date when the endpoint is sunset. |
None
|
alternative
|
Optional[str]
|
The alternative endpoint to redirect to. |
None
|
link
|
Optional[str]
|
The link to the deprecation information (policy or migration guide). |
None
|
links
|
Optional[dict[str, str]]
|
Additional links for deprecation information (newer versions, etc.). |
None
|
brownouts
|
Optional[list[tuple[DateInput, DateInput]]]
|
List of brownout periods. |
None
|
detail
|
Optional[str]
|
Additional detail about the deprecation. |
None
|
response
|
Optional[Callable[[], Response] | Response]
|
Custom response to return. |
None
|
inject_cache_control
|
bool
|
Whether to inject cache control headers. |
False
|
cache_tag
|
Optional[str]
|
Cache tag for the deprecation. |
None
|
brownout_probability
|
float
|
Probability of a brownout. |
0.0
|
progressive_brownout
|
bool
|
Whether to use progressive brownout. |
False
|
Source code in src/fastapi_deprecation/dependencies.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
__getattr__(item)
Pass through attribute accesses to the internal DeprecationConfig for backwards compatibility.