Home / File/ tutorial001_py39.py — fastapi Source File

tutorial001_py39.py — fastapi Source File

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

File python FastAPI Responses 5 imports 1 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  49f928ca_3328_2b1b_a025_ae16399c9b38["tutorial001_py39.py"]
  fda8f0bb_782c_0c24_7ae3_e174de491ade["gzip"]
  49f928ca_3328_2b1b_a025_ae16399c9b38 --> fda8f0bb_782c_0c24_7ae3_e174de491ade
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  49f928ca_3328_2b1b_a025_ae16399c9b38 --> 0dda2280_3359_8460_301c_e98c77e78185
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  49f928ca_3328_2b1b_a025_ae16399c9b38 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  de395a51_26f8_3424_1af0_2f5bef39c893["routing.py"]
  49f928ca_3328_2b1b_a025_ae16399c9b38 --> de395a51_26f8_3424_1af0_2f5bef39c893
  aa28685f_bb97_e988_ff40_3e5385960f32["APIRoute"]
  49f928ca_3328_2b1b_a025_ae16399c9b38 --> aa28685f_bb97_e988_ff40_3e5385960f32
  style 49f928ca_3328_2b1b_a025_ae16399c9b38 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import gzip
from typing import Callable

from fastapi import Body, FastAPI, Request, Response
from fastapi.routing import APIRoute


class GzipRequest(Request):
    async def body(self) -> bytes:
        if not hasattr(self, "_body"):
            body = await super().body()
            if "gzip" in self.headers.getlist("Content-Encoding"):
                body = gzip.decompress(body)
            self._body = body
        return self._body


class GzipRoute(APIRoute):
    def get_route_handler(self) -> Callable:
        original_route_handler = super().get_route_handler()

        async def custom_route_handler(request: Request) -> Response:
            request = GzipRequest(request.scope, request.receive)
            return await original_route_handler(request)

        return custom_route_handler


app = FastAPI()
app.router.route_class = GzipRoute


@app.post("/sum")
async def sum_numbers(numbers: list[int] = Body()):
    return {"sum": sum(numbers)}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does tutorial001_py39.py do?
tutorial001_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 tutorial001_py39.py?
tutorial001_py39.py defines 1 function(s): sum_numbers.
What does tutorial001_py39.py depend on?
tutorial001_py39.py imports 5 module(s): APIRoute, __init__.py, gzip, routing.py, typing.
Where is tutorial001_py39.py in the architecture?
tutorial001_py39.py is located at docs_src/custom_request_and_route/tutorial001_py39.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