Home / File/ _beta_types.py — anthropic-sdk-python Source File

_beta_types.py — anthropic-sdk-python Source File

Architecture documentation for _beta_types.py, a python file in the anthropic-sdk-python codebase. 9 imports, 2 dependents.

File python StreamProtocol SSEDecoder 9 imports 2 dependents 8 classes

Entity Profile

Dependency Diagram

graph LR
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a["_beta_types.py"]
  f7463bf1_ebe5_18ec_cc7d_af03d312451d["_models"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> f7463bf1_ebe5_18ec_cc7d_af03d312451d
  cca712e6_75cf_6203_3b5a_ca9ff687f929["types.beta"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> cca712e6_75cf_6203_3b5a_ca9ff687f929
  1a6768c9_bbca_e747_7ecf_5d7a1fe35633["_parse._response"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> 1a6768c9_bbca_e747_7ecf_5d7a1fe35633
  e2c4c315_43b6_9399_18d2_a13f4c810aa0["_utils._transform"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> e2c4c315_43b6_9399_18d2_a13f4c810aa0
  9b207571_a9e5_cf4b_49e0_05df1668869d["types.beta.parsed_beta_message"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> 9b207571_a9e5_cf4b_49e0_05df1668869d
  61de3873_e3fa_7ab8_6f9b_a172a951fb58["types.beta.beta_citations_delta"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> 61de3873_e3fa_7ab8_6f9b_a172a951fb58
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> 37c05070_ca59_d596_7250_de9d1939227f
  9ba31bda_b3a7_3697_4f5b_cc7d6ca16e80["jiter"]
  6ae52b2b_b80e_bd13_d3c7_f2409e8d863a --> 9ba31bda_b3a7_3697_4f5b_cc7d6ca16e80
  0a07d1cd_f7c3_7747_3560_42a5b3d3bf48["__init__.py"]
  0a07d1cd_f7c3_7747_3560_42a5b3d3bf48 --> 6ae52b2b_b80e_bd13_d3c7_f2409e8d863a
  1e66b543_4a7a_c49e_b6a6_6343193fb272["_beta_messages.py"]
  1e66b543_4a7a_c49e_b6a6_6343193fb272 --> 6ae52b2b_b80e_bd13_d3c7_f2409e8d863a
  style 6ae52b2b_b80e_bd13_d3c7_f2409e8d863a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import TYPE_CHECKING, Any, Dict, Union, Generic, cast
from typing_extensions import List, Literal, Annotated

import jiter

from ..._models import BaseModel, GenericModel
from ...types.beta import (
    BetaRawMessageStopEvent,
    BetaRawMessageDeltaEvent,
    BetaRawMessageStartEvent,
    BetaRawContentBlockStopEvent,
    BetaRawContentBlockDeltaEvent,
    BetaRawContentBlockStartEvent,
)
from .._parse._response import ResponseFormatT
from ..._utils._transform import PropertyInfo
from ...types.beta.parsed_beta_message import ParsedBetaMessage, ParsedBetaContentBlock
from ...types.beta.beta_citations_delta import Citation


class ParsedBetaTextEvent(BaseModel):
    type: Literal["text"]

    text: str
    """The text delta"""

    snapshot: str
    """The entire accumulated text"""

    def parsed_snapshot(self) -> Dict[str, Any]:
        return cast(Dict[str, Any], jiter.from_json(self.snapshot.encode("utf-8"), partial_mode="trailing-strings"))


class BetaCitationEvent(BaseModel):
    type: Literal["citation"]

    citation: Citation
    """The new citation"""

    snapshot: List[Citation]
    """All of the accumulated citations"""


class BetaThinkingEvent(BaseModel):
    type: Literal["thinking"]

    thinking: str
    """The thinking delta"""

    snapshot: str
    """The accumulated thinking so far"""


class BetaSignatureEvent(BaseModel):
    type: Literal["signature"]

    signature: str
    """The signature of the thinking block"""


class BetaInputJsonEvent(BaseModel):
    type: Literal["input_json"]

    partial_json: str
    """A partial JSON string delta

    e.g. `'"San Francisco,'`
    """

    snapshot: object
    """The currently accumulated parsed object.


    e.g. `{'location': 'San Francisco, CA'}`
    """


class BetaCompactionEvent(BaseModel):
    type: Literal["compaction"]

    content: Union[str, None]
    """The compaction content"""


class ParsedBetaMessageStopEvent(BetaRawMessageStopEvent, GenericModel, Generic[ResponseFormatT]):
    type: Literal["message_stop"]

    message: ParsedBetaMessage[ResponseFormatT]


class ParsedBetaContentBlockStopEvent(BetaRawContentBlockStopEvent, GenericModel, Generic[ResponseFormatT]):
    type: Literal["content_block_stop"]

    if TYPE_CHECKING:
        content_block: ParsedBetaContentBlock[ResponseFormatT]
    else:
        content_block: ParsedBetaContentBlock


ParsedBetaMessageStreamEvent = Annotated[
    Union[
        ParsedBetaTextEvent,
        BetaCitationEvent,
        BetaThinkingEvent,
        BetaSignatureEvent,
        BetaInputJsonEvent,
        BetaCompactionEvent,
        BetaRawMessageStartEvent,
        BetaRawMessageDeltaEvent,
        ParsedBetaMessageStopEvent[ResponseFormatT],
        BetaRawContentBlockStartEvent,
        BetaRawContentBlockDeltaEvent,
        ParsedBetaContentBlockStopEvent[ResponseFormatT],
    ],
    PropertyInfo(discriminator="type"),
]

Subdomains

Dependencies

  • _models
  • _parse._response
  • _utils._transform
  • jiter
  • types.beta
  • types.beta.beta_citations_delta
  • types.beta.parsed_beta_message
  • typing
  • typing_extensions

Frequently Asked Questions

What does _beta_types.py do?
_beta_types.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the StreamProtocol domain, SSEDecoder subdomain.
What does _beta_types.py depend on?
_beta_types.py imports 9 module(s): _models, _parse._response, _utils._transform, jiter, types.beta, types.beta.beta_citations_delta, types.beta.parsed_beta_message, typing, and 1 more.
What files import _beta_types.py?
_beta_types.py is imported by 2 file(s): __init__.py, _beta_messages.py.
Where is _beta_types.py in the architecture?
_beta_types.py is located at src/anthropic/lib/streaming/_beta_types.py (domain: StreamProtocol, subdomain: SSEDecoder, 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