Depends()
noun
say it: “dih-PENDZ” /dɪˈpɛndz/
A FastAPI function that marks a route parameter as a dependency: FastAPI calls the function you give it and passes its result in.
What is Depends()?
Depends() marks a parameter as a dependency: FastAPI calls the given function and passes its result in.
def pagination(page: int = 1, size: int = 20):
return {'offset': (page - 1) * size, 'limit': size}
@app.get('/recipes')
def list_recipes(paging: dict = Depends(pagination)):
return find_recipes(**paging)
In a sentence
- “Each route asks for a connection with Depends() and get_db.”
- “Wrapping current_user in Depends() made FastAPI run it before the route.”
Level: Journeyman · More FastAPI terms at this level
Updated