utils.py — fastapi Source File
Architecture documentation for utils.py, a python file in the fastapi codebase. 14 imports, 5 dependents.
Entity Profile
Dependency Diagram
graph LR 1c2c0e68_6ed1_7632_8c35_00818f97b599["utils.py"] aac750d7_00e7_a28d_9e64_89918311078b["__init__.py"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> aac750d7_00e7_a28d_9e64_89918311078b de395a51_26f8_3424_1af0_2f5bef39c893["routing.py"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> de395a51_26f8_3424_1af0_2f5bef39c893 aa28685f_bb97_e988_ff40_3e5385960f32["APIRoute"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> aa28685f_bb97_e988_ff40_3e5385960f32 b423f231_0305_b686_5fea_7c66fe42f25b["re"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> b423f231_0305_b686_5fea_7c66fe42f25b 9c2c9cad_dfd2_7d1a_1c6d_b8a448285db4["warnings"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> 9c2c9cad_dfd2_7d1a_1c6d_b8a448285db4 0dda2280_3359_8460_301c_e98c77e78185["typing"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> 0dda2280_3359_8460_301c_e98c77e78185 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> 534f6e44_61b8_3c38_8b89_6934a6df9802 dc4a1804_f7b4_848b_3280_30523680d7b9["datastructures.py"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> dc4a1804_f7b4_848b_3280_30523680d7b9 c509eb0b_23fb_fa54_c7e7_d4bec7d2f3a9["DefaultPlaceholder"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> c509eb0b_23fb_fa54_c7e7_d4bec7d2f3a9 01c652c5_d85c_f45e_848e_412c94ea4172["exceptions.py"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> 01c652c5_d85c_f45e_848e_412c94ea4172 188b7cd0_ba07_6be7_094a_820e577cc47b["FastAPIDeprecationWarning"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> 188b7cd0_ba07_6be7_094a_820e577cc47b 29cbb417_bbf9_d7ad_9350_e32187134958["PydanticV1NotSupportedError"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> 29cbb417_bbf9_d7ad_9350_e32187134958 b736e30b_692b_1eb3_fc90_f9fee804449e["pydantic.fields"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> b736e30b_692b_1eb3_fc90_f9fee804449e 87f0eda4_1c7f_c164_42ba_f715b8cf0a6b["typing_extensions"] 1c2c0e68_6ed1_7632_8c35_00818f97b599 --> 87f0eda4_1c7f_c164_42ba_f715b8cf0a6b style 1c2c0e68_6ed1_7632_8c35_00818f97b599 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import re
import warnings
from typing import (
TYPE_CHECKING,
Any,
Optional,
Union,
)
import fastapi
from fastapi._compat import (
ModelField,
PydanticSchemaGenerationError,
Undefined,
annotation_is_pydantic_v1,
)
from fastapi.datastructures import DefaultPlaceholder, DefaultType
from fastapi.exceptions import FastAPIDeprecationWarning, PydanticV1NotSupportedError
from pydantic.fields import FieldInfo
from typing_extensions import Literal
from ._compat import v2
if TYPE_CHECKING: # pragma: nocover
from .routing import APIRoute
def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:
if status_code is None:
return True
# Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#patterned-fields-1
if status_code in {
"default",
"1XX",
"2XX",
"3XX",
"4XX",
"5XX",
}:
return True
current_status_code = int(status_code)
return not (current_status_code < 200 or current_status_code in {204, 205, 304})
def get_path_param_names(path: str) -> set[str]:
return set(re.findall("{(.*?)}", path))
_invalid_args_message = (
"Invalid args for response field! Hint: "
"check that {type_} is a valid Pydantic field type. "
"If you are using a return type annotation that is not a valid Pydantic "
"field (e.g. Union[Response, dict, None]) you can disable generating the "
"response model from the type annotation with the path operation decorator "
"parameter response_model=None. Read more: "
"https://fastapi.tiangolo.com/tutorial/response-model/"
)
def create_model_field(
// ... (79 more lines)
Domain
Subdomains
Functions
Dependencies
- APIRoute
- DefaultPlaceholder
- FastAPIDeprecationWarning
- PydanticV1NotSupportedError
- __init__.py
- __init__.py
- datastructures.py
- exceptions.py
- pydantic.fields
- re
- routing.py
- typing
- typing_extensions
- warnings
Imported By
Source
Frequently Asked Questions
What does utils.py do?
utils.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 utils.py?
utils.py defines 8 function(s): create_model_field, deep_dict_update, generate_operation_id_for_path, generate_unique_id, get_path_param_names, get_value_or_default, is_body_allowed_for_status_code, routing.
What does utils.py depend on?
utils.py imports 14 module(s): APIRoute, DefaultPlaceholder, FastAPIDeprecationWarning, PydanticV1NotSupportedError, __init__.py, __init__.py, datastructures.py, exceptions.py, and 6 more.
What files import utils.py?
utils.py is imported by 5 file(s): applications.py, exception_handlers.py, routing.py, utils.py, utils.py.
Where is utils.py in the architecture?
utils.py is located at fastapi/utils.py (domain: FastAPI, subdomain: Routing, directory: fastapi).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free