MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / make_stream_iterator

Function make_stream_iterator

tests/test_streaming.py:394–412  ·  view source on GitHub ↗
(
    content: Iterator[bytes],
    *,
    sync: bool,
    client: Anthropic,
    async_client: AsyncAnthropic,
)

Source from the content-addressed store, hash-verified

392# Unlike make_event_iterator which only parses SSE events using _iter_events(),
393# this helper uses __stream__() to process the full stream pipeline including
394# parsing message objects and converting error events into raised exceptions.
395def make_stream_iterator(
396 content: Iterator[bytes],
397 *,
398 sync: bool,
399 client: Anthropic,
400 async_client: AsyncAnthropic,
401) -> AsyncIterator[object] | Iterator[object]:
402 if sync:
403 return Stream(
404 cast_to=object,
405 client=client,
406 response=httpx2.Response(200, content=content, request=httpx2.Request("GET", "https://example.com")),
407 ).__stream__()
408
409 return AsyncStream(
410 cast_to=object,
411 client=async_client,
412 response=httpx2.Response(200, content=to_aiter(content), request=httpx2.Request("GET", "https://example.com")),
413 ).__stream__()

Callers 1

test_error_typeFunction · 0.85

Calls 4

StreamClass · 0.90
AsyncStreamClass · 0.90
to_aiterFunction · 0.70
__stream__Method · 0.45

Tested by

no test coverage detected