Skip to main content

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

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.state proxy that batches update-state operations
  • 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.pycreate_run() and RunController
  • assistant_stream/assistant_stream_chunk.py – chunk types
  • assistant_stream/state_manager.py, assistant_stream/state_proxy.py – state operations and proxy
  • assistant_stream/serialization/* – response classes and encoders
  • assistant_stream/modules/* – tool call + (optional) LangGraph helpers

License

TBD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assistant_stream_ce-0.0.2.tar.gz (918.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

assistant_stream_ce-0.0.2-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file assistant_stream_ce-0.0.2.tar.gz.

File metadata

  • Download URL: assistant_stream_ce-0.0.2.tar.gz
  • Upload date:
  • Size: 918.4 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

Hashes for assistant_stream_ce-0.0.2.tar.gz
Algorithm Hash digest
SHA256 569b768ba122405f8fa679a7d6aad13fb885512c8d2ee5cb4519da98e3ba3c0e
MD5 d956b81060ded07613112cd465d247e5
BLAKE2b-256 ac826974f9ef2d003e30446545b176530343616739704b0cc781c8fb90685ad6

See more details on using hashes here.

File details

Details for the file assistant_stream_ce-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: assistant_stream_ce-0.0.2-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

Hashes for assistant_stream_ce-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 243d97f6baaa3b683ebd8eaac788e6eab7b970ae732935f474538e5b134816f8
MD5 010bef66fb1dd94da91cbf8ee0cc54a2
BLAKE2b-256 785de5c3893eb4a5925e570eee0d548b6cfb3a061d582cc1a210134d57092ae8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page