Home / Class/ Dependant Class — fastapi Architecture

Dependant Class — fastapi Architecture

Architecture documentation for the Dependant class in models.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  575d42b6_61a5_5351_210d_0e7a8dd0084f["Dependant"]
  28c8873a_5ba4_867f_0824_7abcac157a85["SecurityBase"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|extends| 28c8873a_5ba4_867f_0824_7abcac157a85
  44d16dc7_66bf_1b26_893f_eb0f5695fda1["models.py"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|defined in| 44d16dc7_66bf_1b26_893f_eb0f5695fda1
  cb27fb29_2cde_5c17_c2c8_c6064b4e22e6["oauth_scopes()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| cb27fb29_2cde_5c17_c2c8_c6064b4e22e6
  17fe27f5_9c94_b82c_a8ab_9654ec1462c8["cache_key()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| 17fe27f5_9c94_b82c_a8ab_9654ec1462c8
  3ffc2a2a_8c80_4df2_780c_893c19d3fa14["_uses_scopes()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| 3ffc2a2a_8c80_4df2_780c_893c19d3fa14
  b9e23217_32e9_cc16_af7f_541caf53ba4c["_is_security_scheme()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| b9e23217_32e9_cc16_af7f_541caf53ba4c
  5bc47c6c_50f9_b4d3_d5e1_bf9c756f6ee4["_security_scheme()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| 5bc47c6c_50f9_b4d3_d5e1_bf9c756f6ee4
  ba7c8ff0_53b7_b18d_0af9_eae2bf688d2e["_security_dependencies()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| ba7c8ff0_53b7_b18d_0af9_eae2bf688d2e
  6f587fbc_eb49_f9f0_143e_7c8f60bbc310["is_gen_callable()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| 6f587fbc_eb49_f9f0_143e_7c8f60bbc310
  8498645e_8d43_5486_147b_baa24cf7fb80["is_async_gen_callable()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| 8498645e_8d43_5486_147b_baa24cf7fb80
  3b576417_6926_33b0_dca2_959f7f5317eb["is_coroutine_callable()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| 3b576417_6926_33b0_dca2_959f7f5317eb
  435f5f8b_cc67_fdb0_1de4_2bf09a768e57["computed_scope()"]
  575d42b6_61a5_5351_210d_0e7a8dd0084f -->|method| 435f5f8b_cc67_fdb0_1de4_2bf09a768e57

Relationship Graph

Source Code

fastapi/dependencies/models.py lines 32–193

class Dependant:
    path_params: list[ModelField] = field(default_factory=list)
    query_params: list[ModelField] = field(default_factory=list)
    header_params: list[ModelField] = field(default_factory=list)
    cookie_params: list[ModelField] = field(default_factory=list)
    body_params: list[ModelField] = field(default_factory=list)
    dependencies: list["Dependant"] = field(default_factory=list)
    name: Optional[str] = None
    call: Optional[Callable[..., Any]] = None
    request_param_name: Optional[str] = None
    websocket_param_name: Optional[str] = None
    http_connection_param_name: Optional[str] = None
    response_param_name: Optional[str] = None
    background_tasks_param_name: Optional[str] = None
    security_scopes_param_name: Optional[str] = None
    own_oauth_scopes: Optional[list[str]] = None
    parent_oauth_scopes: Optional[list[str]] = None
    use_cache: bool = True
    path: Optional[str] = None
    scope: Union[Literal["function", "request"], None] = None

    @cached_property
    def oauth_scopes(self) -> list[str]:
        scopes = self.parent_oauth_scopes.copy() if self.parent_oauth_scopes else []
        # This doesn't use a set to preserve order, just in case
        for scope in self.own_oauth_scopes or []:
            if scope not in scopes:
                scopes.append(scope)
        return scopes

    @cached_property
    def cache_key(self) -> DependencyCacheKey:
        scopes_for_cache = (
            tuple(sorted(set(self.oauth_scopes or []))) if self._uses_scopes else ()
        )
        return (
            self.call,
            scopes_for_cache,
            self.computed_scope or "",
        )

    @cached_property
    def _uses_scopes(self) -> bool:
        if self.own_oauth_scopes:
            return True
        if self.security_scopes_param_name is not None:
            return True
        if self._is_security_scheme:
            return True
        for sub_dep in self.dependencies:
            if sub_dep._uses_scopes:
                return True
        return False

    @cached_property
    def _is_security_scheme(self) -> bool:
        if self.call is None:
            return False  # pragma: no cover
        unwrapped = _unwrapped_call(self.call)
        return isinstance(unwrapped, SecurityBase)

    # Mainly to get the type of SecurityBase, but it's the same self.call
    @cached_property
    def _security_scheme(self) -> SecurityBase:
        unwrapped = _unwrapped_call(self.call)
        assert isinstance(unwrapped, SecurityBase)
        return unwrapped

    @cached_property
    def _security_dependencies(self) -> list["Dependant"]:
        security_deps = [dep for dep in self.dependencies if dep._is_security_scheme]
        return security_deps

    @cached_property
    def is_gen_callable(self) -> bool:
        if self.call is None:
            return False  # pragma: no cover
        if inspect.isgeneratorfunction(
            _impartial(self.call)
        ) or inspect.isgeneratorfunction(_unwrapped_call(self.call)):
            return True

Extends

Frequently Asked Questions

What is the Dependant class?
Dependant is a class in the fastapi codebase, defined in fastapi/dependencies/models.py.
Where is Dependant defined?
Dependant is defined in fastapi/dependencies/models.py at line 32.
What does Dependant extend?
Dependant extends SecurityBase.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free