AsyncMessageStreamManager Class — anthropic-sdk-python Architecture
Architecture documentation for the AsyncMessageStreamManager class in _messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD b39d416a_2a20_5d73_a91e_777d8fe3f331["AsyncMessageStreamManager"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef["_messages.py"] b39d416a_2a20_5d73_a91e_777d8fe3f331 -->|defined in| 738ef0a0_4e16_ebf0_9c79_a17daa58ddef 5d7a37b5_015f_cc3e_f917_58722830fc78["__init__()"] b39d416a_2a20_5d73_a91e_777d8fe3f331 -->|method| 5d7a37b5_015f_cc3e_f917_58722830fc78 2a6efa2c_1a87_ffe6_9e30_bfcc51f039a7["__aenter__()"] b39d416a_2a20_5d73_a91e_777d8fe3f331 -->|method| 2a6efa2c_1a87_ffe6_9e30_bfcc51f039a7 cef5c823_47b1_ea5d_e607_eb0cb87bf232["__aexit__()"] b39d416a_2a20_5d73_a91e_777d8fe3f331 -->|method| cef5c823_47b1_ea5d_e607_eb0cb87bf232
Relationship Graph
Source Code
src/anthropic/lib/streaming/_messages.py lines 294–328
class AsyncMessageStreamManager(Generic[ResponseFormatT]):
"""Wrapper over AsyncMessageStream that is returned by `.stream()`
so that an async context manager can be used without `await`ing the
original client call.
```py
async with client.messages.stream(...) as stream:
async for chunk in stream:
...
```
"""
def __init__(
self,
api_request: Awaitable[AsyncStream[RawMessageStreamEvent]],
*,
output_format: ResponseFormatT | NotGiven = NOT_GIVEN,
) -> None:
self.__stream: AsyncMessageStream[ResponseFormatT] | None = None
self.__api_request = api_request
self.__output_format = output_format
async def __aenter__(self) -> AsyncMessageStream[ResponseFormatT]:
raw_stream = await self.__api_request
self.__stream = AsyncMessageStream(raw_stream, output_format=self.__output_format)
return self.__stream
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
if self.__stream is not None:
await self.__stream.close()
Domain
Defined In
Source
Frequently Asked Questions
What is the AsyncMessageStreamManager class?
AsyncMessageStreamManager is a class in the anthropic-sdk-python codebase, defined in src/anthropic/lib/streaming/_messages.py.
Where is AsyncMessageStreamManager defined?
AsyncMessageStreamManager is defined in src/anthropic/lib/streaming/_messages.py at line 294.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free