Home / File/ tutorial007_py39.py — fastapi Source File

tutorial007_py39.py — fastapi Source File

Architecture documentation for tutorial007_py39.py, a python file in the fastapi codebase. 3 imports, 0 dependents.

File python FastAPI Routing 3 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  6f1b737b_b9f8_4d44_684d_41ca4b921191["tutorial007_py39.py"]
  05832956_b384_ff7e_ef60_abebb23f9723["secrets"]
  6f1b737b_b9f8_4d44_684d_41ca4b921191 --> 05832956_b384_ff7e_ef60_abebb23f9723
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  6f1b737b_b9f8_4d44_684d_41ca4b921191 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  35c4ea20_c454_5afd_6cda_f0818bbcc650["__init__.py"]
  6f1b737b_b9f8_4d44_684d_41ca4b921191 --> 35c4ea20_c454_5afd_6cda_f0818bbcc650
  style 6f1b737b_b9f8_4d44_684d_41ca4b921191 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import secrets

from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import HTTPBasic, HTTPBasicCredentials

app = FastAPI()

security = HTTPBasic()


def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
    current_username_bytes = credentials.username.encode("utf8")
    correct_username_bytes = b"stanleyjobson"
    is_correct_username = secrets.compare_digest(
        current_username_bytes, correct_username_bytes
    )
    current_password_bytes = credentials.password.encode("utf8")
    correct_password_bytes = b"swordfish"
    is_correct_password = secrets.compare_digest(
        current_password_bytes, correct_password_bytes
    )
    if not (is_correct_username and is_correct_password):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Incorrect username or password",
            headers={"WWW-Authenticate": "Basic"},
        )
    return credentials.username


@app.get("/users/me")
def read_current_user(username: str = Depends(get_current_username)):
    return {"username": username}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does tutorial007_py39.py do?
tutorial007_py39.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Routing subdomain.
What functions are defined in tutorial007_py39.py?
tutorial007_py39.py defines 2 function(s): get_current_username, read_current_user.
What does tutorial007_py39.py depend on?
tutorial007_py39.py imports 3 module(s): __init__.py, __init__.py, secrets.
Where is tutorial007_py39.py in the architecture?
tutorial007_py39.py is located at docs_src/security/tutorial007_py39.py (domain: FastAPI, subdomain: Routing, directory: docs_src/security).

Analyze Your Own Codebase

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

Try Supermodel Free