_messages.py — anthropic-sdk-python Source File
Architecture documentation for _messages.py, a python file in the anthropic-sdk-python codebase. 23 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 738ef0a0_4e16_ebf0_9c79_a17daa58ddef["_messages.py"] 0fe13bcd_521d_1fdd_3edc_21cd47da8ca0["_types.py"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> 0fe13bcd_521d_1fdd_3edc_21cd47da8ca0 25f5e18c_763b_8f7d_5a87_8b7bc536af01["TextEvent"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> 25f5e18c_763b_8f7d_5a87_8b7bc536af01 ea0f0107_27eb_0921_30cd_0d6abecdf844["CitationEvent"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> ea0f0107_27eb_0921_30cd_0d6abecdf844 b367c66c_5121_33c5_ca2b_7fd424066bae["ThinkingEvent"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> b367c66c_5121_33c5_ca2b_7fd424066bae 3e849f57_0c81_23c3_828c_3c8a5fb0e9f7["InputJsonEvent"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> 3e849f57_0c81_23c3_828c_3c8a5fb0e9f7 5cc72e4b_36d5_9c25_a10b_4506b594a1bb["SignatureEvent"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> 5cc72e4b_36d5_9c25_a10b_4506b594a1bb 316615ac_a4ff_b667_0f10_e6b88360b7a3["ParsedMessageStopEvent"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> 316615ac_a4ff_b667_0f10_e6b88360b7a3 bdf20814_1cb5_4f1b_91e9_09c73cfeff76["ParsedContentBlockStopEvent"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> bdf20814_1cb5_4f1b_91e9_09c73cfeff76 d8af20ea_d6b2_e21a_499d_eb81af499916["types"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> d8af20ea_d6b2_e21a_499d_eb81af499916 e07c5fdf_8abe_8389_4a76_d5d0afb02821["_utils"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> e07c5fdf_8abe_8389_4a76_d5d0afb02821 f7463bf1_ebe5_18ec_cc7d_af03d312451d["_models"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> f7463bf1_ebe5_18ec_cc7d_af03d312451d c3e7c071_e102_f915_e24c_2a05dc6fb82d["_streaming"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> c3e7c071_e102_f915_e24c_2a05dc6fb82d 833ef528_0950_9d44_c941_0e6bff38aa60["_utils._utils"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> 833ef528_0950_9d44_c941_0e6bff38aa60 1a6768c9_bbca_e747_7ecf_5d7a1fe35633["_parse._response"] 738ef0a0_4e16_ebf0_9c79_a17daa58ddef --> 1a6768c9_bbca_e747_7ecf_5d7a1fe35633 style 738ef0a0_4e16_ebf0_9c79_a17daa58ddef fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
from types import TracebackType
from typing import TYPE_CHECKING, Any, Type, Generic, Callable, cast
from typing_extensions import Self, Iterator, Awaitable, AsyncIterator, assert_never
import httpx
from pydantic import BaseModel
from anthropic.types.tool_use_block import ToolUseBlock
from anthropic.types.server_tool_use_block import ServerToolUseBlock
from ._types import (
TextEvent,
CitationEvent,
ThinkingEvent,
InputJsonEvent,
SignatureEvent,
ParsedMessageStopEvent,
ParsedMessageStreamEvent,
ParsedContentBlockStopEvent,
)
from ...types import RawMessageStreamEvent
from ..._types import NOT_GIVEN, NotGiven
from ..._utils import consume_sync_iterator, consume_async_iterator
from ..._models import build, construct_type, construct_type_unchecked
from ..._streaming import Stream, AsyncStream
from ..._utils._utils import is_given
from .._parse._response import ResponseFormatT, parse_text
from ...types.parsed_message import ParsedMessage, ParsedContentBlock
class MessageStream(Generic[ResponseFormatT]):
text_stream: Iterator[str]
"""Iterator over just the text deltas in the stream.
```py
for text in stream.text_stream:
print(text, end="", flush=True)
print()
```
"""
def __init__(
self,
raw_stream: Stream[RawMessageStreamEvent],
output_format: ResponseFormatT | NotGiven,
) -> None:
self._raw_stream = raw_stream
self.text_stream = self.__stream_text__()
self._iterator = self.__stream__()
self.__final_message_snapshot: ParsedMessage[ResponseFormatT] | None = None
self.__output_format = output_format
@property
def response(self) -> httpx.Response:
return self._raw_stream.response
@property
def request_id(self) -> str | None:
// ... (459 more lines)
Domain
Subdomains
Functions
Dependencies
- CitationEvent
- InputJsonEvent
- ParsedContentBlockStopEvent
- ParsedMessageStopEvent
- SignatureEvent
- TextEvent
- ThinkingEvent
- _models
- _parse._response
- _streaming
- _types.py
- _utils
- _utils._utils
- anthropic.types.server_tool_use_block
- anthropic.types.tool_use_block
- httpx
- jiter
- pydantic
- types
- types
- types.parsed_message
- typing
- typing_extensions
Imported By
Source
Frequently Asked Questions
What does _messages.py do?
_messages.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the StreamProtocol domain, AsyncStreaming subdomain.
What functions are defined in _messages.py?
_messages.py defines 2 function(s): accumulate_event, build_events.
What does _messages.py depend on?
_messages.py imports 23 module(s): CitationEvent, InputJsonEvent, ParsedContentBlockStopEvent, ParsedMessageStopEvent, SignatureEvent, TextEvent, ThinkingEvent, _models, and 15 more.
What files import _messages.py?
_messages.py is imported by 1 file(s): __init__.py.
Where is _messages.py in the architecture?
_messages.py is located at src/anthropic/lib/streaming/_messages.py (domain: StreamProtocol, subdomain: AsyncStreaming, directory: src/anthropic/lib/streaming).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free