Skip to main content

Dependant

This class represents a dependency in an application, encapsulating information about how a particular callable (function, method, or class) should be invoked, including its parameters, sub-dependencies, and security requirements. It manages various types of parameters (path, query, header, cookie, body) and recursively handles nested dependencies. The class also provides properties to determine the callable's type (generator, async generator, coroutine) and its associated security scopes.

Attributes

AttributeTypeDescription
path_paramslist[ModelField] = []Stores a list of ModelField objects representing path parameters extracted from the request, used to validate and inject values into the dependent callable.
query_paramslist[ModelField] = []Stores a list of ModelField objects representing query parameters extracted from the request, used to validate and inject values into the dependent callable.
header_paramslist[ModelField] = []Stores a list of ModelField objects representing header parameters extracted from the request, used to validate and inject values into the dependent callable.
cookie_paramslist[ModelField] = []Stores a list of ModelField objects representing cookie parameters extracted from the request, used to validate and inject values into the dependent callable.
body_paramslist[ModelField] = []Stores a list of ModelField objects representing body parameters extracted from the request, used to validate and inject values into the dependent callable.
dependencieslist["Dependant"] = []Stores a list of other Dependant objects that this Dependant relies on, forming a dependency chain for resolution.
name`strNone` = null
call`Callable[..., Any]None` = null
request_param_name`strNone` = null
websocket_param_name`strNone` = null
http_connection_param_name`strNone` = null
response_param_name`strNone` = null
background_tasks_param_name`strNone` = null
security_scopes_param_name`strNone` = null
own_oauth_scopes`list[str]None` = null
parent_oauth_scopes`list[str]None` = null
use_cachebool = trueA boolean indicating whether the result of this Dependant's callable should be cached, improving performance for repeated calls.
path`strNone` = null
scope`Literal["function", "request"]None` = null

Methods


oauth_scopes()

@classmethod
def oauth_scopes() - > list[str]

Retrieves the combined OAuth scopes required by this dependant and its parent dependants. This method ensures that scopes are unique while preserving their order.

Returns

TypeDescription
list[str]A list of unique OAuth scope strings, maintaining the order of appearance.

cache_key()

@classmethod
def cache_key() - > DependencyCacheKey

Generates a unique key for caching the dependant's resolution. This key is based on the callable, sorted unique OAuth scopes (if applicable), and the computed scope.

Returns

TypeDescription
DependencyCacheKeyA tuple representing the cache key, consisting of the callable, sorted unique OAuth scopes, and the computed scope string.

is_gen_callable()

@classmethod
def is_gen_callable() - > bool

Determines if the dependant's callable is a generator function. This is used to identify callables that yield values, typically for dependency injection with cleanup.

Returns

TypeDescription
boolTrue if the callable is a generator function, False otherwise.

is_async_gen_callable()

@classmethod
def is_async_gen_callable() - > bool

Determines if the dependant's callable is an asynchronous generator function. This is used to identify async callables that yield values, typically for dependency injection with asynchronous cleanup.

Returns

TypeDescription
boolTrue if the callable is an asynchronous generator function, False otherwise.

is_coroutine_callable()

@classmethod
def is_coroutine_callable() - > bool

Determines if the dependant's callable is a coroutine function. This is used to identify asynchronous functions that need to be awaited.

Returns

TypeDescription
boolTrue if the callable is a coroutine function, False otherwise.

computed_scope()

@classmethod
def computed_scope() - > str | None

Calculates the scope of the dependant, which can be 'function' or 'request'. This determines the lifecycle of the dependency.

Returns

TypeDescription
`strNone`