Home / File/ tutorial004_py39.py — fastapi Source File

tutorial004_py39.py — fastapi Source File

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

File python FastAPI Responses 8 imports 10 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  a1cb859f_602f_c57b_9972_9c8d6cb843e2["tutorial004_py39.py"]
  e973e384_8276_b242_eb98_1c0b79a84e68["datetime"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> e973e384_8276_b242_eb98_1c0b79a84e68
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> 0dda2280_3359_8460_301c_e98c77e78185
  822acfd3_718b_c215_daf1_986b6791f3bd["jwt"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> 822acfd3_718b_c215_daf1_986b6791f3bd
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  35c4ea20_c454_5afd_6cda_f0818bbcc650["__init__.py"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> 35c4ea20_c454_5afd_6cda_f0818bbcc650
  96400ec7_7fe7_41d2_404e_d92498b1ac31["jwt.exceptions"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> 96400ec7_7fe7_41d2_404e_d92498b1ac31
  640a3b96_2dad_7fba_4cb0_187a74ec8604["pwdlib"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> 640a3b96_2dad_7fba_4cb0_187a74ec8604
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  a1cb859f_602f_c57b_9972_9c8d6cb843e2 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style a1cb859f_602f_c57b_9972_9c8d6cb843e2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from datetime import datetime, timedelta, timezone
from typing import Union

import jwt
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from jwt.exceptions import InvalidTokenError
from pwdlib import PasswordHash
from pydantic import BaseModel

# to get a string like this run:
# openssl rand -hex 32
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30


fake_users_db = {
    "johndoe": {
        "username": "johndoe",
        "full_name": "John Doe",
        "email": "johndoe@example.com",
        "hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$wagCPXjifgvUFBzq4hqe3w$CYaIb8sB+wtD+Vu/P4uod1+Qof8h+1g7bbDlBID48Rc",
        "disabled": False,
    }
}


class Token(BaseModel):
    access_token: str
    token_type: str


class TokenData(BaseModel):
    username: Union[str, None] = None


class User(BaseModel):
    username: str
    email: Union[str, None] = None
    full_name: Union[str, None] = None
    disabled: Union[bool, None] = None


class UserInDB(User):
    hashed_password: str


password_hash = PasswordHash.recommended()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

app = FastAPI()


def verify_password(plain_password, hashed_password):
    return password_hash.verify(plain_password, hashed_password)


def get_password_hash(password):
// ... (82 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does tutorial004_py39.py do?
tutorial004_py39.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in tutorial004_py39.py?
tutorial004_py39.py defines 10 function(s): authenticate_user, create_access_token, get_current_active_user, get_current_user, get_password_hash, get_user, login_for_access_token, read_own_items, read_users_me, verify_password.
What does tutorial004_py39.py depend on?
tutorial004_py39.py imports 8 module(s): __init__.py, __init__.py, datetime, jwt, jwt.exceptions, pwdlib, pydantic, typing.
Where is tutorial004_py39.py in the architecture?
tutorial004_py39.py is located at docs_src/security/tutorial004_py39.py (domain: FastAPI, subdomain: Responses, directory: docs_src/security).

Analyze Your Own Codebase

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

Try Supermodel Free