Global Dependencies and Sub-Dependencies
Apply dependencies across an entire app or router, chain sub-dependencies, and cache dependency results within a request to build clean, layered FastAPI applications.
Scaling Up Dependencies
You can attach a dependency to a single route, but real apps need to apply checks broadly. FastAPI supports dependencies at the app, router, and route levels, plus dependencies that depend on other dependencies.
App-Level Dependencies
Pass dependencies=[...] to the FastAPI constructor to run them for every request. Useful for global logging or API-key checks.
from fastapi import FastAPI, Depends
async def verify_key():
...
app = FastAPI(dependencies=[Depends(verify_key)])All lessons in this course
- Understanding Dependencies in FastAPI
- Injecting Common Dependencies
- Class-based & Yield Dependencies
- Global Dependencies and Sub-Dependencies