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
more documentation at assistant-stream-ce.
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
Metadata
Release files for assistant-stream-ce 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| assistant_stream_ce-0.0.2.tar.gz | 918.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| assistant_stream_ce-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 940.2 kB
Release files / assistant_stream_ce-0.0.2.tar.gz
| Download URL | assistant_stream_ce-0.0.2.tar.gz |
|---|---|
| Size | 918.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
569b768ba122405f8fa679a7d6aad13fb885512c8d2ee5cb4519da98e3ba3c0e
|
|
BLAKE2b-256 checksum How to use checksums |
ac826974f9ef2d003e30446545b176530343616739704b0cc781c8fb90685ad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / assistant_stream_ce-0.0.2-py3-none-any.whl
| Download URL | assistant_stream_ce-0.0.2-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
243d97f6baaa3b683ebd8eaac788e6eab7b970ae732935f474538e5b134816f8
|
|
BLAKE2b-256 checksum How to use checksums |
785de5c3893eb4a5925e570eee0d548b6cfb3a061d582cc1a210134d57092ae8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|