Dependency injection means your path operation functions declare the things they require to work — "dependencies" — and FastAPI takes care of doing whatever is needed to provide them. This is useful for shared logic, sharing database connections, and enforcing security, authentication, and role requirements, all while minimizing code repetition. A dependency, or "dependable", is just a function that can take all the same parameters a path operation function can take, such as async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100). Declare use of it by importing Depends from fastapi and annotating a parameter, as in commons: Annotated[dict, Depends(common_parameters)]; the same dependency can serve several path operations, as the tutorial does for /items/ and /users/. Keep each dependency small and single-purpose so they compose cleanly — that preference is Koskamo editorial guidance. Scope: FastAPI. Reviewed October 4, 2026.
Dependency injection with Depends
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- fastapi.tiangolo.com
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.