Home / Function/ main() — anthropic-sdk-python Function Reference

main() — anthropic-sdk-python Function Reference

Architecture documentation for the main() function in messages_stream.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  8e29318e_89d7_05c2_0582_cb63877231d0["main()"]
  1ef13462_9f23_5822_ba66_eff32dde079f["messages_stream.py"]
  8e29318e_89d7_05c2_0582_cb63877231d0 -->|defined in| 1ef13462_9f23_5822_ba66_eff32dde079f
  style 8e29318e_89d7_05c2_0582_cb63877231d0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

examples/messages_stream.py lines 10–33

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())

Subdomains

Frequently Asked Questions

What does main() do?
main() is a function in the anthropic-sdk-python codebase, defined in examples/messages_stream.py.
Where is main() defined?
main() is defined in examples/messages_stream.py at line 10.

Analyze Your Own Codebase

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

Try Supermodel Free