text_completions_streaming.py — anthropic-sdk-python Source File
Architecture documentation for text_completions_streaming.py, a python file in the anthropic-sdk-python codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8ffeac10_981a_383f_b7d5_30faeda2740a["text_completions_streaming.py"] 22e54b11_c61c_96dc_bf33_dfc7151750e9["asyncio"] 8ffeac10_981a_383f_b7d5_30faeda2740a --> 22e54b11_c61c_96dc_bf33_dfc7151750e9 d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"] 8ffeac10_981a_383f_b7d5_30faeda2740a --> d10c5377_2939_0f0b_cc44_8759393f2853 style 8ffeac10_981a_383f_b7d5_30faeda2740a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
#!/usr/bin/env -S poetry run python
import asyncio
from anthropic import AI_PROMPT, HUMAN_PROMPT, Anthropic, APIStatusError, AsyncAnthropic
client = Anthropic()
async_client = AsyncAnthropic()
question = """
Hey Claude! How can I recursively list all files in a directory in Python?
"""
def sync_stream() -> None:
stream = client.completions.create(
prompt=f"{HUMAN_PROMPT} {question}{AI_PROMPT}",
model="claude-sonnet-4-5-20250929",
stream=True,
max_tokens_to_sample=300,
)
for completion in stream:
print(completion.completion, end="", flush=True)
print()
async def async_stream() -> None:
stream = await async_client.completions.create(
prompt=f"{HUMAN_PROMPT} {question}{AI_PROMPT}",
model="claude-sonnet-4-5-20250929",
stream=True,
max_tokens_to_sample=300,
)
async for completion in stream:
print(completion.completion, end="", flush=True)
print()
def stream_error() -> None:
try:
client.completions.create(
prompt=f"{HUMAN_PROMPT} {question}{AI_PROMPT}",
model="claude-unknown-model",
stream=True,
max_tokens_to_sample=300,
)
except APIStatusError as err:
print(f"Caught API status error with response body: {err.response.text}")
sync_stream()
asyncio.run(async_stream())
stream_error()
Domain
Subdomains
Dependencies
- anthropic
- asyncio
Source
Frequently Asked Questions
What does text_completions_streaming.py do?
text_completions_streaming.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 text_completions_streaming.py?
text_completions_streaming.py defines 3 function(s): async_stream, stream_error, sync_stream.
What does text_completions_streaming.py depend on?
text_completions_streaming.py imports 2 module(s): anthropic, asyncio.
Where is text_completions_streaming.py in the architecture?
text_completions_streaming.py is located at examples/text_completions_streaming.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