tutorial003_py310.py — fastapi Source File
Architecture documentation for tutorial003_py310.py, a python file in the fastapi codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 9dc29258_63d8_2a6a_b7bd_2461b5eff8ea["tutorial003_py310.py"] 1f0e807e_8e8f_35d7_c6d0_300886df5c17["time"] 9dc29258_63d8_2a6a_b7bd_2461b5eff8ea --> 1f0e807e_8e8f_35d7_c6d0_300886df5c17 07d79a2e_d4e9_0bbb_be90_936274444c8c["collections.abc"] 9dc29258_63d8_2a6a_b7bd_2461b5eff8ea --> 07d79a2e_d4e9_0bbb_be90_936274444c8c 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 9dc29258_63d8_2a6a_b7bd_2461b5eff8ea --> 534f6e44_61b8_3c38_8b89_6934a6df9802 de395a51_26f8_3424_1af0_2f5bef39c893["routing.py"] 9dc29258_63d8_2a6a_b7bd_2461b5eff8ea --> de395a51_26f8_3424_1af0_2f5bef39c893 aa28685f_bb97_e988_ff40_3e5385960f32["APIRoute"] 9dc29258_63d8_2a6a_b7bd_2461b5eff8ea --> aa28685f_bb97_e988_ff40_3e5385960f32 style 9dc29258_63d8_2a6a_b7bd_2461b5eff8ea fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import time
from collections.abc import Callable
from fastapi import APIRouter, FastAPI, Request, Response
from fastapi.routing import APIRoute
class TimedRoute(APIRoute):
def get_route_handler(self) -> Callable:
original_route_handler = super().get_route_handler()
async def custom_route_handler(request: Request) -> Response:
before = time.time()
response: Response = await original_route_handler(request)
duration = time.time() - before
response.headers["X-Response-Time"] = str(duration)
print(f"route duration: {duration}")
print(f"route response: {response}")
print(f"route response headers: {response.headers}")
return response
return custom_route_handler
app = FastAPI()
router = APIRouter(route_class=TimedRoute)
@app.get("/")
async def not_timed():
return {"message": "Not timed"}
@router.get("/timed")
async def timed():
return {"message": "It's the time of my life"}
app.include_router(router)
Domain
Subdomains
Functions
Classes
Dependencies
- APIRoute
- __init__.py
- collections.abc
- routing.py
- time
Source
Frequently Asked Questions
What does tutorial003_py310.py do?
tutorial003_py310.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 tutorial003_py310.py?
tutorial003_py310.py defines 2 function(s): not_timed, timed.
What does tutorial003_py310.py depend on?
tutorial003_py310.py imports 5 module(s): APIRoute, __init__.py, collections.abc, routing.py, time.
Where is tutorial003_py310.py in the architecture?
tutorial003_py310.py is located at docs_src/custom_request_and_route/tutorial003_py310.py (domain: FastAPI, subdomain: Responses, directory: docs_src/custom_request_and_route).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free