Home / File/ _streaming.py — anthropic-sdk-python Source File

_streaming.py — anthropic-sdk-python Source File

Architecture documentation for _streaming.py, a python file in the anthropic-sdk-python codebase. 14 imports, 4 dependents.

File python AnthropicClient SyncAPI 14 imports 4 dependents 3 functions 7 classes

Entity Profile

Dependency Diagram

graph LR
  8d141d22_ab1c_b4a1_744c_99e460d07454["_streaming.py"]
  6dadb144_3070_6111_357f_214554108905["__init__.py"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 6dadb144_3070_6111_357f_214554108905
  3a4e7de9_0222_597c_a697_7ff97bd0dafc["_client.py"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 3a4e7de9_0222_597c_a697_7ff97bd0dafc
  0517492b_78c2_27e9_22ae_aae3b5f0e93e["Anthropic"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 0517492b_78c2_27e9_22ae_aae3b5f0e93e
  0fd89929_7b38_b43a_7bae_43e09dda2e19["AsyncAnthropic"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 0fd89929_7b38_b43a_7bae_43e09dda2e19
  4def3491_fbdc_6572_1c5b_08ea936b7fe7["lib.streaming"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 4def3491_fbdc_6572_1c5b_08ea936b7fe7
  31e60ad8_cac8_652d_176d_4f7cf7dda1ad["_base_client.py"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 31e60ad8_cac8_652d_176d_4f7cf7dda1ad
  90b87fb1_b7c6_6103_fd94_a71d362551d6["abc"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 90b87fb1_b7c6_6103_fd94_a71d362551d6
  28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5["json"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5
  506d0594_2a0d_4f14_1041_ed428dcfcac8["inspect"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 506d0594_2a0d_4f14_1041_ed428dcfcac8
  dee4291e_ab30_b635_c404_0df76c542e94["warnings"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> dee4291e_ab30_b635_c404_0df76c542e94
  2eb1aa7f_c778_4d68_0a26_a102fadd9638["__init__.py"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 2eb1aa7f_c778_4d68_0a26_a102fadd9638
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 37c05070_ca59_d596_7250_de9d1939227f
  9c26e8a9_1ad2_1174_876a_1fc500ce0eaf["httpx"]
  8d141d22_ab1c_b4a1_744c_99e460d07454 --> 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf
  style 8d141d22_ab1c_b4a1_744c_99e460d07454 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

# Note: initially copied from https://github.com/florimondmanca/httpx-sse/blob/master/src/httpx_sse/_decoders.py
from __future__ import annotations

import abc
import json
import inspect
import warnings
from types import TracebackType
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, AsyncIterator, cast
from typing_extensions import Self, Protocol, TypeGuard, override, get_origin, runtime_checkable

import httpx

from ._utils import is_dict, extract_type_var_from_base

if TYPE_CHECKING:
    from ._client import Anthropic, AsyncAnthropic


_T = TypeVar("_T")


class _SyncStreamMeta(abc.ABCMeta):
    @override
    def __instancecheck__(self, instance: Any) -> bool:
        # we override the `isinstance()` check for `Stream`
        # as a previous version of the `MessageStream` class
        # inherited from `Stream` & without this workaround,
        # changing it to not inherit would be a breaking change.

        from .lib.streaming import MessageStream

        if isinstance(instance, MessageStream):
            warnings.warn(
                "Using `isinstance()` to check if a `MessageStream` object is an instance of `Stream` is deprecated & will be removed in the next major version",
                DeprecationWarning,
                stacklevel=2,
            )
            return True

        return False


class Stream(Generic[_T], metaclass=_SyncStreamMeta):
    """Provides the core interface to iterate over a synchronous stream response."""

    response: httpx.Response

    _decoder: SSEBytesDecoder

    def __init__(
        self,
        *,
        cast_to: type[_T],
        response: httpx.Response,
        client: Anthropic,
    ) -> None:
        self.response = response
        self._cast_to = cast_to
        self._client = client
// ... (384 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does _streaming.py do?
_streaming.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, SyncAPI subdomain.
What functions are defined in _streaming.py?
_streaming.py defines 3 function(s): _client, extract_stream_chunk_type, is_stream_class_type.
What does _streaming.py depend on?
_streaming.py imports 14 module(s): Anthropic, AsyncAnthropic, __init__.py, __init__.py, _base_client.py, _client.py, abc, httpx, and 6 more.
What files import _streaming.py?
_streaming.py is imported by 4 file(s): _base_client.py, _client.py, _legacy_response.py, _response.py.
Where is _streaming.py in the architecture?
_streaming.py is located at src/anthropic/_streaming.py (domain: AnthropicClient, subdomain: SyncAPI, directory: src/anthropic).

Analyze Your Own Codebase

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

Try Supermodel Free