Don't call it directly, FastAPI will call it for you, just pass the object
directly.
TYPE:Optional[Callable[..., Any]]DEFAULT:None
use_cache
By default, after a dependency is called the first time in a request, if
the dependency is declared again for the rest of the request (for example
if the dependency is needed by several dependencies), the value will be
re-used for the rest of the request.
Set use_cache to False to disable this behavior and ensure the
dependency is called again (if declared more than once) in the same request.
defDepends(# noqa: N802dependency:Annotated[Optional[Callable[...,Any]],Doc(""" A "dependable" callable (like a function). Don't call it directly, FastAPI will call it for you, just pass the object directly. """),]=None,*,use_cache:Annotated[bool,Doc(""" By default, after a dependency is called the first time in a request, if the dependency is declared again for the rest of the request (for example if the dependency is needed by several dependencies), the value will be re-used for the rest of the request. Set `use_cache` to `False` to disable this behavior and ensure the dependency is called again (if declared more than once) in the same request. """),]=True,)->Any:""" Declare a FastAPI dependency. It takes a single "dependable" callable (like a function). Don't call it directly, FastAPI will call it for you. Read more about it in the [FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/). **Example** ```python from typing import Annotated from fastapi import Depends, FastAPI app = FastAPI() async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100): return {"q": q, "skip": skip, "limit": limit} @app.get("/items/") async def read_items(commons: Annotated[dict, Depends(common_parameters)]): return commons ``` """returnparams.Depends(dependency=dependency,use_cache=use_cache)
The only difference with a regular dependency is that it can declare OAuth2
scopes that will be integrated with OpenAPI and the automatic UI docs (by default
at /docs).
It takes a single "dependable" callable (like a function).
Don't call it directly, FastAPI will call it for you.
Don't call it directly, FastAPI will call it for you, just pass the object
directly.
TYPE:Optional[Callable[..., Any]]DEFAULT:None
scopes
OAuth2 scopes required for the path operation that uses this Security
dependency.
The term "scope" comes from the OAuth2 specification, it seems to be
intentionaly vague and interpretable. It normally refers to permissions,
in cases to roles.
These scopes are integrated with OpenAPI (and the API docs at /docs).
So they are visible in the OpenAPI specification.
)
TYPE:Optional[Sequence[str]]DEFAULT:None
use_cache
By default, after a dependency is called the first time in a request, if
the dependency is declared again for the rest of the request (for example
if the dependency is needed by several dependencies), the value will be
re-used for the rest of the request.
Set use_cache to False to disable this behavior and ensure the
dependency is called again (if declared more than once) in the same request.
defSecurity(# noqa: N802dependency:Annotated[Optional[Callable[...,Any]],Doc(""" A "dependable" callable (like a function). Don't call it directly, FastAPI will call it for you, just pass the object directly. """),]=None,*,scopes:Annotated[Optional[Sequence[str]],Doc(""" OAuth2 scopes required for the *path operation* that uses this Security dependency. The term "scope" comes from the OAuth2 specification, it seems to be intentionaly vague and interpretable. It normally refers to permissions, in cases to roles. These scopes are integrated with OpenAPI (and the API docs at `/docs`). So they are visible in the OpenAPI specification. ) """),]=None,use_cache:Annotated[bool,Doc(""" By default, after a dependency is called the first time in a request, if the dependency is declared again for the rest of the request (for example if the dependency is needed by several dependencies), the value will be re-used for the rest of the request. Set `use_cache` to `False` to disable this behavior and ensure the dependency is called again (if declared more than once) in the same request. """),]=True,)->Any:""" Declare a FastAPI Security dependency. The only difference with a regular dependency is that it can declare OAuth2 scopes that will be integrated with OpenAPI and the automatic UI docs (by default at `/docs`). It takes a single "dependable" callable (like a function). Don't call it directly, FastAPI will call it for you. Read more about it in the [FastAPI docs for Security](https://fastapi.tiangolo.com/tutorial/security/) and in the [FastAPI docs for OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/). **Example** ```python from typing import Annotated from fastapi import Depends, FastAPI from .db import User from .security import get_current_active_user app = FastAPI() @app.get("/users/me/items/") async def read_own_items( current_user: Annotated[User, Security(get_current_active_user, scopes=["items"])] ): return [{"item_id": "Foo", "owner": current_user.username}] ``` """returnparams.Security(dependency=dependency,scopes=scopes,use_cache=use_cache)