Home / Class/ ResponseContextManager Class — anthropic-sdk-python Architecture

ResponseContextManager Class — anthropic-sdk-python Architecture

Architecture documentation for the ResponseContextManager class in _response.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  41dc657b_1a82_2bcd_9b39_71fd91f7adb3["ResponseContextManager"]
  2e9c15bb_de03_aa91_93be_0e05db0a552e["_response.py"]
  41dc657b_1a82_2bcd_9b39_71fd91f7adb3 -->|defined in| 2e9c15bb_de03_aa91_93be_0e05db0a552e
  29af83a0_b731_e3f3_7777_4185ba321724["__init__()"]
  41dc657b_1a82_2bcd_9b39_71fd91f7adb3 -->|method| 29af83a0_b731_e3f3_7777_4185ba321724
  a4215d0b_de43_1e98_d85e_09ef80deaa5a["__enter__()"]
  41dc657b_1a82_2bcd_9b39_71fd91f7adb3 -->|method| a4215d0b_de43_1e98_d85e_09ef80deaa5a
  1ffb6318_7a3b_46dd_9b58_8d1a7d58800e["__exit__()"]
  41dc657b_1a82_2bcd_9b39_71fd91f7adb3 -->|method| 1ffb6318_7a3b_46dd_9b58_8d1a7d58800e

Relationship Graph

Source Code

src/anthropic/_response.py lines 639–660

class ResponseContextManager(Generic[_APIResponseT]):
    """Context manager for ensuring that a request is not made
    until it is entered and that the response will always be closed
    when the context manager exits
    """

    def __init__(self, request_func: Callable[[], _APIResponseT]) -> None:
        self._request_func = request_func
        self.__response: _APIResponseT | None = None

    def __enter__(self) -> _APIResponseT:
        self.__response = self._request_func()
        return self.__response

    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc: BaseException | None,
        exc_tb: TracebackType | None,
    ) -> None:
        if self.__response is not None:
            self.__response.close()

Frequently Asked Questions

What is the ResponseContextManager class?
ResponseContextManager is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_response.py.
Where is ResponseContextManager defined?
ResponseContextManager is defined in src/anthropic/_response.py at line 639.

Analyze Your Own Codebase

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

Try Supermodel Free