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

HttpxBinaryResponseContent Class — anthropic-sdk-python Architecture

Architecture documentation for the HttpxBinaryResponseContent class in _legacy_response.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  707108e1_1591_e5c4_7fa0_ca26831eab86["HttpxBinaryResponseContent"]
  f3a9224d_bdab_aa4b_9f5e_877302fb10bc["_legacy_response.py"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|defined in| f3a9224d_bdab_aa4b_9f5e_877302fb10bc
  8c194826_727b_e7c4_e80f_e89e76fe4eeb["__init__()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 8c194826_727b_e7c4_e80f_e89e76fe4eeb
  bf996e96_ba48_42a8_146e_6c4161ab2ed4["content()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| bf996e96_ba48_42a8_146e_6c4161ab2ed4
  d582dd51_4708_666d_1a4d_81a58d79e4fe["text()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| d582dd51_4708_666d_1a4d_81a58d79e4fe
  3b6a24a9_1dba_cc23_a311_3aedfa773dfd["encoding()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 3b6a24a9_1dba_cc23_a311_3aedfa773dfd
  65939782_2880_4507_0802_ad9ba14f478b["charset_encoding()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 65939782_2880_4507_0802_ad9ba14f478b
  6f77bac1_8784_c84a_9d98_b667e36cf350["json()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 6f77bac1_8784_c84a_9d98_b667e36cf350
  36f44ace_f237_9472_1e64_2638bcb61484["read()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 36f44ace_f237_9472_1e64_2638bcb61484
  45fe0d69_db3d_a57c_6c23_db57ac73d759["iter_bytes()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 45fe0d69_db3d_a57c_6c23_db57ac73d759
  dc146308_8235_57ca_2117_9456faad79c3["iter_text()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| dc146308_8235_57ca_2117_9456faad79c3
  47cbf18e_c4c9_9a0d_8089_83cf9f6b5e34["iter_lines()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 47cbf18e_c4c9_9a0d_8089_83cf9f6b5e34
  584114e8_dc61_1088_adf3_c870e3255724["iter_raw()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 584114e8_dc61_1088_adf3_c870e3255724
  0a61dc46_3f02_41b3_b5a0_da3c9ec89abe["write_to_file()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 0a61dc46_3f02_41b3_b5a0_da3c9ec89abe
  59ca99bd_2882_998f_1bd3_9fc565c030f2["stream_to_file()"]
  707108e1_1591_e5c4_7fa0_ca26831eab86 -->|method| 59ca99bd_2882_998f_1bd3_9fc565c030f2

Relationship Graph

Source Code

src/anthropic/_legacy_response.py lines 409–511

class HttpxBinaryResponseContent:
    response: httpx.Response

    def __init__(self, response: httpx.Response) -> None:
        self.response = response

    @property
    def content(self) -> bytes:
        return self.response.content

    @property
    def text(self) -> str:
        return self.response.text

    @property
    def encoding(self) -> str | None:
        return self.response.encoding

    @property
    def charset_encoding(self) -> str | None:
        return self.response.charset_encoding

    def json(self, **kwargs: Any) -> Any:
        return self.response.json(**kwargs)

    def read(self) -> bytes:
        return self.response.read()

    def iter_bytes(self, chunk_size: int | None = None) -> Iterator[bytes]:
        return self.response.iter_bytes(chunk_size)

    def iter_text(self, chunk_size: int | None = None) -> Iterator[str]:
        return self.response.iter_text(chunk_size)

    def iter_lines(self) -> Iterator[str]:
        return self.response.iter_lines()

    def iter_raw(self, chunk_size: int | None = None) -> Iterator[bytes]:
        return self.response.iter_raw(chunk_size)

    def write_to_file(
        self,
        file: str | os.PathLike[str],
    ) -> None:
        """Write the output to the given file.

        Accepts a filename or any path-like object, e.g. pathlib.Path

        Note: if you want to stream the data to the file instead of writing
        all at once then you should use `.with_streaming_response` when making
        the API request, e.g. `client.with_streaming_response.foo().stream_to_file('my_filename.txt')`
        """
        with open(file, mode="wb") as f:
            for data in self.response.iter_bytes():
                f.write(data)

    @deprecated(
        "Due to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead"
    )
    def stream_to_file(
        self,
        file: str | os.PathLike[str],
        *,
        chunk_size: int | None = None,
    ) -> None:
        with open(file, mode="wb") as f:
            for data in self.response.iter_bytes(chunk_size):
                f.write(data)

    def close(self) -> None:
        return self.response.close()

    async def aread(self) -> bytes:
        return await self.response.aread()

    async def aiter_bytes(self, chunk_size: int | None = None) -> AsyncIterator[bytes]:
        return self.response.aiter_bytes(chunk_size)

    async def aiter_text(self, chunk_size: int | None = None) -> AsyncIterator[str]:
        return self.response.aiter_text(chunk_size)

Frequently Asked Questions

What is the HttpxBinaryResponseContent class?
HttpxBinaryResponseContent is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_legacy_response.py.
Where is HttpxBinaryResponseContent defined?
HttpxBinaryResponseContent is defined in src/anthropic/_legacy_response.py at line 409.

Analyze Your Own Codebase

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

Try Supermodel Free