get_dependant() — fastapi Function Reference
Architecture documentation for the get_dependant() function in utils.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 097a7e41_8095_d61f_b849_128514c58040["get_dependant()"] 9e602cbf_3139_86ae_5666_97b8806942de["utils.py"] 097a7e41_8095_d61f_b849_128514c58040 -->|defined in| 9e602cbf_3139_86ae_5666_97b8806942de 3a3fcbe8_4556_0002_0c59_0917c6099b2b["get_parameterless_sub_dependant()"] 3a3fcbe8_4556_0002_0c59_0917c6099b2b -->|calls| 097a7e41_8095_d61f_b849_128514c58040 fc3220b9_b8bc_99f6_605f_911723c78183["solve_dependencies()"] fc3220b9_b8bc_99f6_605f_911723c78183 -->|calls| 097a7e41_8095_d61f_b849_128514c58040 0df3979a_d2ac_6dd9_1bb1_6629b89a941b["__init__()"] 0df3979a_d2ac_6dd9_1bb1_6629b89a941b -->|calls| 097a7e41_8095_d61f_b849_128514c58040 d8b4fb83_3521_0b7e_fcfa_0c7f161ca116["__init__()"] d8b4fb83_3521_0b7e_fcfa_0c7f161ca116 -->|calls| 097a7e41_8095_d61f_b849_128514c58040 5c5ae7c4_0bc7_5a7e_fd52_1b6189493272["get_path_param_names()"] 097a7e41_8095_d61f_b849_128514c58040 -->|calls| 5c5ae7c4_0bc7_5a7e_fd52_1b6189493272 6a4e43ff_0eba_2bed_5c6f_cda57d19a022["get_typed_signature()"] 097a7e41_8095_d61f_b849_128514c58040 -->|calls| 6a4e43ff_0eba_2bed_5c6f_cda57d19a022 3a586946_6748_d24d_8ee8_d3c9dbd7e696["analyze_param()"] 097a7e41_8095_d61f_b849_128514c58040 -->|calls| 3a586946_6748_d24d_8ee8_d3c9dbd7e696 2f0d48f2_69ad_85f8_c209_9aadf3b96b05["add_non_field_param_to_dependency()"] 097a7e41_8095_d61f_b849_128514c58040 -->|calls| 2f0d48f2_69ad_85f8_c209_9aadf3b96b05 206d3183_bfaa_d681_38b1_42f425b7a046["add_param_to_fields()"] 097a7e41_8095_d61f_b849_128514c58040 -->|calls| 206d3183_bfaa_d681_38b1_42f425b7a046 style 097a7e41_8095_d61f_b849_128514c58040 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/dependencies/utils.py lines 257–329
def get_dependant(
*,
path: str,
call: Callable[..., Any],
name: Optional[str] = None,
own_oauth_scopes: Optional[list[str]] = None,
parent_oauth_scopes: Optional[list[str]] = None,
use_cache: bool = True,
scope: Union[Literal["function", "request"], None] = None,
) -> Dependant:
dependant = Dependant(
call=call,
name=name,
path=path,
use_cache=use_cache,
scope=scope,
own_oauth_scopes=own_oauth_scopes,
parent_oauth_scopes=parent_oauth_scopes,
)
current_scopes = (parent_oauth_scopes or []) + (own_oauth_scopes or [])
path_param_names = get_path_param_names(path)
endpoint_signature = get_typed_signature(call)
signature_params = endpoint_signature.parameters
for param_name, param in signature_params.items():
is_path_param = param_name in path_param_names
param_details = analyze_param(
param_name=param_name,
annotation=param.annotation,
value=param.default,
is_path_param=is_path_param,
)
if param_details.depends is not None:
assert param_details.depends.dependency
if (
(dependant.is_gen_callable or dependant.is_async_gen_callable)
and dependant.computed_scope == "request"
and param_details.depends.scope == "function"
):
assert dependant.call
raise DependencyScopeError(
f'The dependency "{dependant.call.__name__}" has a scope of '
'"request", it cannot depend on dependencies with scope "function".'
)
sub_own_oauth_scopes: list[str] = []
if isinstance(param_details.depends, params.Security):
if param_details.depends.scopes:
sub_own_oauth_scopes = list(param_details.depends.scopes)
sub_dependant = get_dependant(
path=path,
call=param_details.depends.dependency,
name=param_name,
own_oauth_scopes=sub_own_oauth_scopes,
parent_oauth_scopes=current_scopes,
use_cache=param_details.depends.use_cache,
scope=param_details.depends.scope,
)
dependant.dependencies.append(sub_dependant)
continue
if add_non_field_param_to_dependency(
param_name=param_name,
type_annotation=param_details.type_annotation,
dependant=dependant,
):
assert param_details.field is None, (
f"Cannot specify multiple FastAPI annotations for {param_name!r}"
)
continue
assert param_details.field is not None
if isinstance(param_details.field.field_info, params.Body):
dependant.body_params.append(param_details.field)
else:
add_param_to_fields(field=param_details.field, dependant=dependant)
return dependant
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does get_dependant() do?
get_dependant() is a function in the fastapi codebase, defined in fastapi/dependencies/utils.py.
Where is get_dependant() defined?
get_dependant() is defined in fastapi/dependencies/utils.py at line 257.
What does get_dependant() call?
get_dependant() calls 5 function(s): add_non_field_param_to_dependency, add_param_to_fields, analyze_param, get_path_param_names, get_typed_signature.
What calls get_dependant()?
get_dependant() is called by 4 function(s): __init__, __init__, get_parameterless_sub_dependant, solve_dependencies.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free