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

Method iter_bytes

src/anthropic/_streaming.py:383–391  ·  view source on GitHub ↗

Given an iterator that yields raw binary data, iterate over it & yield every event encountered

(self, iterator: Iterator[bytes])

Source from the content-addressed store, hash-verified

381 self._raw = []
382
383 def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
384 """Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
385 for chunk in self._iter_chunks(iterator):
386 # Split before decoding so splitlines() only uses \r and \n
387 for raw_line in chunk.splitlines():
388 line = raw_line.decode("utf-8")
389 sse = self.decode(line)
390 if sse:
391 yield sse
392
393 def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]:
394 """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""

Callers 2

_iter_eventsMethod · 0.45
raw_eventsMethod · 0.45

Calls 2

_iter_chunksMethod · 0.95
decodeMethod · 0.95

Tested by

no test coverage detected