Home / File/ tutorial015_an_py39.py — fastapi Source File

tutorial015_an_py39.py — fastapi Source File

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

File python FastAPI Routing 4 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  f1decedc_f412_832f_3a88_f10278007e2f["tutorial015_an_py39.py"]
  de7ad334_ca8a_57df_c9b1_c007a1804821["random"]
  f1decedc_f412_832f_3a88_f10278007e2f --> de7ad334_ca8a_57df_c9b1_c007a1804821
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  f1decedc_f412_832f_3a88_f10278007e2f --> 0dda2280_3359_8460_301c_e98c77e78185
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  f1decedc_f412_832f_3a88_f10278007e2f --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  f1decedc_f412_832f_3a88_f10278007e2f --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style f1decedc_f412_832f_3a88_f10278007e2f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import random
from typing import Annotated, Union

from fastapi import FastAPI
from pydantic import AfterValidator

app = FastAPI()

data = {
    "isbn-9781529046137": "The Hitchhiker's Guide to the Galaxy",
    "imdb-tt0371724": "The Hitchhiker's Guide to the Galaxy",
    "isbn-9781439512982": "Isaac Asimov: The Complete Stories, Vol. 2",
}


def check_valid_id(id: str):
    if not id.startswith(("isbn-", "imdb-")):
        raise ValueError('Invalid ID format, it must start with "isbn-" or "imdb-"')
    return id


@app.get("/items/")
async def read_items(
    id: Annotated[Union[str, None], AfterValidator(check_valid_id)] = None,
):
    if id:
        item = data.get(id)
    else:
        id, item = random.choice(list(data.items()))
    return {"id": id, "name": item}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does tutorial015_an_py39.py do?
tutorial015_an_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 tutorial015_an_py39.py?
tutorial015_an_py39.py defines 2 function(s): check_valid_id, read_items.
What does tutorial015_an_py39.py depend on?
tutorial015_an_py39.py imports 4 module(s): __init__.py, pydantic, random, typing.
Where is tutorial015_an_py39.py in the architecture?
tutorial015_an_py39.py is located at docs_src/query_params_str_validations/tutorial015_an_py39.py (domain: FastAPI, subdomain: Routing, directory: docs_src/query_params_str_validations).

Analyze Your Own Codebase

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

Try Supermodel Free