Home / Function/ __init__() — fastapi Function Reference

__init__() — fastapi Function Reference

Architecture documentation for the __init__() function in oauth2.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  8bbd2977_d668_7711_0e32_049fb7ad434f["__init__()"]
  5023758b_9456_fafe_dbb4_30deaf7720ac["OAuth2"]
  8bbd2977_d668_7711_0e32_049fb7ad434f -->|defined in| 5023758b_9456_fafe_dbb4_30deaf7720ac
  style 8bbd2977_d668_7711_0e32_049fb7ad434f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fastapi/security/oauth2.py lines 343–399

    def __init__(
        self,
        *,
        flows: Annotated[
            Union[OAuthFlowsModel, dict[str, dict[str, Any]]],
            Doc(
                """
                The dictionary of OAuth2 flows.
                """
            ),
        ] = OAuthFlowsModel(),
        scheme_name: Annotated[
            Optional[str],
            Doc(
                """
                Security scheme name.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                """
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                """
                Security scheme description.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                """
            ),
        ] = None,
        auto_error: Annotated[
            bool,
            Doc(
                """
                By default, if no HTTP Authorization header is provided, required for
                OAuth2 authentication, it will automatically cancel the request and
                send the client an error.

                If `auto_error` is set to `False`, when the HTTP Authorization header
                is not available, instead of erroring out, the dependency result will
                be `None`.

                This is useful when you want to have optional authentication.

                It is also useful when you want to have authentication that can be
                provided in one of multiple optional ways (for example, with OAuth2
                or in a cookie).
                """
            ),
        ] = True,
    ):
        self.model = OAuth2Model(
            flows=cast(OAuthFlowsModel, flows), description=description
        )
        self.scheme_name = scheme_name or self.__class__.__name__
        self.auto_error = auto_error

Domain

Subdomains

Frequently Asked Questions

What does __init__() do?
__init__() is a function in the fastapi codebase, defined in fastapi/security/oauth2.py.
Where is __init__() defined?
__init__() is defined in fastapi/security/oauth2.py at line 343.

Analyze Your Own Codebase

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

Try Supermodel Free