messages_stream.py — anthropic-sdk-python Source File
Architecture documentation for messages_stream.py, a python file in the anthropic-sdk-python codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 1ef13462_9f23_5822_ba66_eff32dde079f["messages_stream.py"] 22e54b11_c61c_96dc_bf33_dfc7151750e9["asyncio"] 1ef13462_9f23_5822_ba66_eff32dde079f --> 22e54b11_c61c_96dc_bf33_dfc7151750e9 d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"] 1ef13462_9f23_5822_ba66_eff32dde079f --> d10c5377_2939_0f0b_cc44_8759393f2853 style 1ef13462_9f23_5822_ba66_eff32dde079f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
#!/usr/bin/env -S rye run python
import asyncio
from anthropic import AsyncAnthropic
client = AsyncAnthropic()
async def main() -> None:
async with client.messages.stream(
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Say hello there!",
}
],
model="claude-sonnet-4-5-20250929",
) as stream:
async for event in stream:
if event.type == "text":
print(event.text, end="", flush=True)
elif event.type == "content_block_stop":
print()
print("\ncontent block finished accumulating:", event.content_block)
print()
# you can still get the accumulated final message outside of
# the context manager, as long as the entire stream was consumed
# inside of the context manager
accumulated = await stream.get_final_message()
print("accumulated message: ", accumulated.to_json())
asyncio.run(main())
Domain
Subdomains
Functions
Dependencies
- anthropic
- asyncio
Source
Frequently Asked Questions
What does messages_stream.py do?
messages_stream.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 messages_stream.py?
messages_stream.py defines 1 function(s): main.
What does messages_stream.py depend on?
messages_stream.py imports 2 module(s): anthropic, asyncio.
Where is messages_stream.py in the architecture?
messages_stream.py is located at examples/messages_stream.py (domain: AnthropicClient, subdomain: SyncAPI, directory: examples).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free