responses.py — fastapi Source File
Architecture documentation for responses.py, a python file in the fastapi codebase. 4 imports, 68 dependents.
Entity Profile
Dependency Diagram
graph LR 967b6712_70e2_f5fa_f671_7c149857a445["responses.py"] 0dda2280_3359_8460_301c_e98c77e78185["typing"] 967b6712_70e2_f5fa_f671_7c149857a445 --> 0dda2280_3359_8460_301c_e98c77e78185 e5a24867_6a9b_cc44_1a92_bc955a4ceb50["starlette.responses"] 967b6712_70e2_f5fa_f671_7c149857a445 --> e5a24867_6a9b_cc44_1a92_bc955a4ceb50 a1f35025_d82c_3646_98f5_0589d6a8101b["ujson"] 967b6712_70e2_f5fa_f671_7c149857a445 --> a1f35025_d82c_3646_98f5_0589d6a8101b 9de9d538_b3d9_ff4a_53fa_f662e9eee826["orjson"] 967b6712_70e2_f5fa_f671_7c149857a445 --> 9de9d538_b3d9_ff4a_53fa_f662e9eee826 1888f47c_e1ad_f494_b3f0_911d6f30cae4["tutorial001_py39.py"] 1888f47c_e1ad_f494_b3f0_911d6f30cae4 --> 967b6712_70e2_f5fa_f671_7c149857a445 e9761ca5_d5c6_a0d2_70d3_a5f274f3f794["tutorial002_py310.py"] e9761ca5_d5c6_a0d2_70d3_a5f274f3f794 --> 967b6712_70e2_f5fa_f671_7c149857a445 b46bad94_4871_36f0_39bf_c1559a6a08d3["tutorial002_py39.py"] b46bad94_4871_36f0_39bf_c1559a6a08d3 --> 967b6712_70e2_f5fa_f671_7c149857a445 21b708b8_ccef_6041_0f86_9c9d59b4933f["tutorial003_py39.py"] 21b708b8_ccef_6041_0f86_9c9d59b4933f --> 967b6712_70e2_f5fa_f671_7c149857a445 4bbf47d8_52f0_1e65_0a61_87cefa57145a["tutorial004_py310.py"] 4bbf47d8_52f0_1e65_0a61_87cefa57145a --> 967b6712_70e2_f5fa_f671_7c149857a445 ba978e75_3e11_ca0b_6b1c_ad03a9f47ea6["tutorial004_py39.py"] ba978e75_3e11_ca0b_6b1c_ad03a9f47ea6 --> 967b6712_70e2_f5fa_f671_7c149857a445 1a2832b7_389e_add1_d53f_2a923e640d40["tutorial001_an_py310.py"] 1a2832b7_389e_add1_d53f_2a923e640d40 --> 967b6712_70e2_f5fa_f671_7c149857a445 bed886d6_b05b_dce2_8ea5_14f4adbbdd0d["tutorial001_an_py39.py"] bed886d6_b05b_dce2_8ea5_14f4adbbdd0d --> 967b6712_70e2_f5fa_f671_7c149857a445 00858b0f_a247_db13_5645_aa6771c60e93["tutorial001_py310.py"] 00858b0f_a247_db13_5645_aa6771c60e93 --> 967b6712_70e2_f5fa_f671_7c149857a445 0e599186_7a9b_90b8_83be_9f4628cb1ef9["tutorial001_py39.py"] 0e599186_7a9b_90b8_83be_9f4628cb1ef9 --> 967b6712_70e2_f5fa_f671_7c149857a445 style 967b6712_70e2_f5fa_f671_7c149857a445 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Any
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
try:
import ujson
except ImportError: # pragma: nocover
ujson = None # type: ignore
try:
import orjson
except ImportError: # pragma: nocover
orjson = None # type: ignore
class UJSONResponse(JSONResponse):
"""
JSON response using the high-performance ujson library to serialize data to JSON.
Read more about it in the
[FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
"""
def render(self, content: Any) -> bytes:
assert ujson is not None, "ujson must be installed to use UJSONResponse"
return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
class ORJSONResponse(JSONResponse):
"""
JSON response using the high-performance orjson library to serialize data to JSON.
Read more about it in the
[FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
"""
def render(self, content: Any) -> bytes:
assert orjson is not None, "orjson must be installed to use ORJSONResponse"
return orjson.dumps(
content, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY
)
Domain
Subdomains
Classes
Dependencies
- orjson
- starlette.responses
- typing
- ujson
Imported By
- fastapi/__init__.py
- tests/test_additional_responses_custom_validationerror.py
- tests/test_additional_responses_response_class.py
- tests/test_default_response_class.py
- tests/test_default_response_class_router.py
- tests/test_dependency_after_yield_streaming.py
- tests/test_dependency_contextmanager.py
- tests/test_dependency_yield_scope.py
- tests/test_extra_routes.py
- tests/test_include_route.py
- tests/test_include_router_defaults_overrides.py
- tests/test_orjson_response_class.py
- tests/test_response_class_no_mediatype.py
- tests/test_response_code_no_body.py
- tests/test_response_dependency.py
- tests/test_response_model_as_return_annotation.py
- tests/test_tutorial/test_advanced_middleware/test_tutorial003.py
- docs_src/additional_status_codes/tutorial001_an_py310.py
- docs_src/additional_status_codes/tutorial001_an_py39.py
- docs_src/response_directly/tutorial001_py310.py
- docs_src/additional_status_codes/tutorial001_py310.py
- docs_src/response_cookies/tutorial001_py39.py
- docs_src/websockets/tutorial001_py39.py
- docs_src/additional_status_codes/tutorial001_py39.py
- docs_src/custom_response/tutorial001_py39.py
- docs_src/templates/tutorial001_py39.py
- docs_src/response_headers/tutorial001_py39.py
- docs_src/response_directly/tutorial001_py39.py
- docs_src/additional_responses/tutorial001_py39.py
- docs_src/custom_response/tutorial001b_py39.py
- docs_src/websockets/tutorial002_an_py310.py
- docs_src/request_files/tutorial002_an_py39.py
- docs_src/websockets/tutorial002_an_py39.py
- docs_src/additional_responses/tutorial002_py310.py
- docs_src/websockets/tutorial002_py310.py
- docs_src/request_files/tutorial002_py39.py
- docs_src/additional_responses/tutorial002_py39.py
- docs_src/custom_response/tutorial002_py39.py
- docs_src/websockets/tutorial002_py39.py
- docs_src/response_model/tutorial003_02_py39.py
- docs_src/response_model/tutorial003_03_py39.py
- docs_src/response_model/tutorial003_04_py310.py
- docs_src/response_model/tutorial003_04_py39.py
- docs_src/response_model/tutorial003_05_py310.py
- docs_src/response_model/tutorial003_05_py39.py
- docs_src/request_files/tutorial003_an_py39.py
- docs_src/additional_responses/tutorial003_py39.py
- docs_src/handling_errors/tutorial003_py39.py
- docs_src/websockets/tutorial003_py39.py
- docs_src/request_files/tutorial003_py39.py
- docs_src/custom_response/tutorial003_py39.py
- docs_src/additional_responses/tutorial004_py310.py
- docs_src/handling_errors/tutorial004_py39.py
- docs_src/additional_responses/tutorial004_py39.py
- docs_src/custom_response/tutorial004_py39.py
- docs_src/handling_errors/tutorial005_py39.py
- docs_src/custom_response/tutorial005_py39.py
- docs_src/custom_response/tutorial006_py39.py
- docs_src/custom_response/tutorial006b_py39.py
- docs_src/custom_response/tutorial006c_py39.py
- docs_src/custom_response/tutorial007_py39.py
- docs_src/custom_response/tutorial008_py39.py
- docs_src/custom_response/tutorial009_py39.py
- docs_src/custom_response/tutorial009b_py39.py
- docs_src/custom_response/tutorial010_py39.py
- docs_src/dependencies/tutorial013_an_py310.py
- docs_src/dependencies/tutorial014_an_py310.py
- fastapi/openapi/utils.py
Source
Frequently Asked Questions
What does responses.py do?
responses.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 responses.py?
responses.py defines 2 function(s): orjson, ujson.
What does responses.py depend on?
responses.py imports 4 module(s): orjson, starlette.responses, typing, ujson.
What files import responses.py?
responses.py is imported by 68 file(s): __init__.py, test_additional_responses_custom_validationerror.py, test_additional_responses_response_class.py, test_default_response_class.py, test_default_response_class_router.py, test_dependency_after_yield_streaming.py, test_dependency_contextmanager.py, test_dependency_yield_scope.py, and 60 more.
Where is responses.py in the architecture?
responses.py is located at fastapi/responses.py (domain: FastAPI, subdomain: Responses, directory: fastapi).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free