A documented version of the assistant-stream library, taken from the assistant-ui monorepo.
Project description
Credits
This is code taken from the main assistant-ui repo. The assistant-stream library does not have its own documentation at the moment, and this is the gap this project tries to fill.
assistant-stream
Typed streaming helpers for building assistant backends in Python.
This library focuses on one job: turn an async "run" function into a structured stream of events that can be encoded for different client transports (FastAPI/Starlette streaming responses, assistant-ui streams, or OpenAI-style SSE).
Key features
- Typed chunks (
text-delta,tool-call-*,tool-result,update-state,source,data,error) - FastAPI / Starlette friendly response classes:
DataStreamResponse(assistant-ui newline protocol)AssistantTransportResponse(SSE with JSON payloads)OpenAIStreamResponse(minimal OpenAI-like chunk stream)
- State syncing via a convenient
controller.stateproxy that batchesupdate-stateoperations - Tool call streaming with incremental args and final results
- Optional LangGraph helpers (available when LangGraph/LangChain deps are installed)
Installation
pip install assistant-stream
For local development:
pip install -e .
Minimal usage (no web framework)
from assistant_stream import create_run
async def run(controller):
controller.append_text("Hello ")
controller.append_text("world!")
stream = create_run(run)
async for chunk in stream:
print(chunk)
FastAPI example (assistant-ui Data Stream)
from fastapi import FastAPI
from assistant_stream import create_run
from assistant_stream.serialization.data_stream import DataStreamResponse
app = FastAPI()
@app.get("/chat")
async def chat():
async def run(controller):
controller.append_text("Hello from FastAPI!")
return DataStreamResponse(create_run(run))
Tool call example
import json
from assistant_stream import create_run
async def run(controller):
tool = await controller.add_tool_call("search")
tool.append_args_text(json.dumps({"q": "fastapi streaming"}))
tool.set_response({"results": ["..."]})
stream = create_run(run)
State syncing example
from assistant_stream import create_run
async def run(controller):
controller.state = {"draft": "", "messages": []}
controller.state["draft"] += "Hello"
controller.state["messages"].append({"role": "assistant", "content": "Hello"})
stream = create_run(run, state={})
Documentation (Sphinx)
The repository includes modular Sphinx docs in docs/.
Build HTML docs:
cd docs
make html
# open docs/build/html/index.html
Package layout
assistant_stream/create_run.py–create_run()andRunControllerassistant_stream/assistant_stream_chunk.py– chunk typesassistant_stream/state_manager.py,assistant_stream/state_proxy.py– state operations and proxyassistant_stream/serialization/*– response classes and encodersassistant_stream/modules/*– tool call + (optional) LangGraph helpers
License
TBD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file assistant_stream_ce-0.0.1.tar.gz.
File metadata
- Download URL: assistant_stream_ce-0.0.1.tar.gz
- Upload date:
- Size: 901.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
295fb000abf58823a66cb2653e770979eff0a9f1be94b67b6d4549c6e5751ce4
|
|
| MD5 |
7ba87a78a330153b2941d1029fc034f0
|
|
| BLAKE2b-256 |
ef8a29d7892b18c2c73925b8f6c3d1cbefab18303e84c617fb45cf9822a39e28
|
File details
Details for the file assistant_stream_ce-0.0.1-py3-none-any.whl.
File metadata
- Download URL: assistant_stream_ce-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b276450279630d1667ed64d07bcef18e6319651187fa843afb8a84dfc426c33b
|
|
| MD5 |
b1e60579c8b0f43697d13b5a90eadf6f
|
|
| BLAKE2b-256 |
b29354db2e901e241e37c00cdff8f49c2e568364d0bb6e94e951f7a98a71902e
|