Home / File/ asyncexitstack.py — fastapi Source File

asyncexitstack.py — fastapi Source File

Architecture documentation for asyncexitstack.py, a python file in the fastapi codebase. 2 imports, 1 dependents.

File python Middleware Protocols 2 imports 1 dependents 1 classes

Entity Profile

Dependency Diagram

graph LR
  2efae956_b294_abd7_b5c6_794690e86bb5["asyncexitstack.py"]
  a88eb002_9197_73f3_410d_ee5315767f34["contextlib"]
  2efae956_b294_abd7_b5c6_794690e86bb5 --> a88eb002_9197_73f3_410d_ee5315767f34
  36d278c1_a64a_e028_c7e5_2c6ad533f4c8["starlette.types"]
  2efae956_b294_abd7_b5c6_794690e86bb5 --> 36d278c1_a64a_e028_c7e5_2c6ad533f4c8
  6c1867f2_34c4_b2ed_5639_41766e6fd7ce["applications.py"]
  6c1867f2_34c4_b2ed_5639_41766e6fd7ce --> 2efae956_b294_abd7_b5c6_794690e86bb5
  style 2efae956_b294_abd7_b5c6_794690e86bb5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from contextlib import AsyncExitStack

from starlette.types import ASGIApp, Receive, Scope, Send


# Used mainly to close files after the request is done, dependencies are closed
# in their own AsyncExitStack
class AsyncExitStackMiddleware:
    def __init__(
        self, app: ASGIApp, context_name: str = "fastapi_middleware_astack"
    ) -> None:
        self.app = app
        self.context_name = context_name

    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        async with AsyncExitStack() as stack:
            scope[self.context_name] = stack
            await self.app(scope, receive, send)

Domain

Subdomains

Dependencies

  • contextlib
  • starlette.types

Frequently Asked Questions

What does asyncexitstack.py do?
asyncexitstack.py is a source file in the fastapi codebase, written in python. It belongs to the Middleware domain, Protocols subdomain.
What does asyncexitstack.py depend on?
asyncexitstack.py imports 2 module(s): contextlib, starlette.types.
What files import asyncexitstack.py?
asyncexitstack.py is imported by 1 file(s): applications.py.
Where is asyncexitstack.py in the architecture?
asyncexitstack.py is located at fastapi/middleware/asyncexitstack.py (domain: Middleware, subdomain: Protocols, directory: fastapi/middleware).

Analyze Your Own Codebase

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

Try Supermodel Free