tutorial007_an_py39.py — fastapi Source File
Architecture documentation for tutorial007_an_py39.py, a python file in the fastapi codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a3de186a_b6a5_46b3_f084_3661a4356671["tutorial007_an_py39.py"] 05832956_b384_ff7e_ef60_abebb23f9723["secrets"] a3de186a_b6a5_46b3_f084_3661a4356671 --> 05832956_b384_ff7e_ef60_abebb23f9723 0dda2280_3359_8460_301c_e98c77e78185["typing"] a3de186a_b6a5_46b3_f084_3661a4356671 --> 0dda2280_3359_8460_301c_e98c77e78185 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] a3de186a_b6a5_46b3_f084_3661a4356671 --> 534f6e44_61b8_3c38_8b89_6934a6df9802 35c4ea20_c454_5afd_6cda_f0818bbcc650["__init__.py"] a3de186a_b6a5_46b3_f084_3661a4356671 --> 35c4ea20_c454_5afd_6cda_f0818bbcc650 style a3de186a_b6a5_46b3_f084_3661a4356671 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import secrets
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import HTTPBasic, HTTPBasicCredentials
app = FastAPI()
security = HTTPBasic()
def get_current_username(
credentials: Annotated[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: Annotated[str, Depends(get_current_username)]):
return {"username": username}
Domain
Subdomains
Dependencies
- __init__.py
- __init__.py
- secrets
- typing
Source
Frequently Asked Questions
What does tutorial007_an_py39.py do?
tutorial007_an_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 tutorial007_an_py39.py?
tutorial007_an_py39.py defines 2 function(s): get_current_username, read_current_user.
What does tutorial007_an_py39.py depend on?
tutorial007_an_py39.py imports 4 module(s): __init__.py, __init__.py, secrets, typing.
Where is tutorial007_an_py39.py in the architecture?
tutorial007_an_py39.py is located at docs_src/security/tutorial007_an_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