Tiny demo focused on one thing: open a realtime collaboration session from Python and mutate it via HTTP.
main.py is currently hardcoded for the local @y/hub server in ./yjs-hub.
It uses the pip-installed superdoc-sdk CLI companion by default
and the async Python SDK client (AsyncSuperDocClient)
and writes /download output to examples/editor/collaboration/backends/fastapi/.superdoc-state/download.docx.
cd examples/editor/collaboration/backends/fastapi
uv venv .venv
source .venv/bin/activate
uv pip install -r requirements.txtFrom the FastAPI folder:
cd examples/editor/collaboration/backends/fastapi
./run-yjs-hub.shOr manually:
cd examples/editor/collaboration/backends/fastapi/yjs-hub
pnpm install --ignore-workspace --lockfile=false
pnpm run deps:up
pnpm run devdeps:up requires Docker daemon running (Docker Desktop on macOS).
If you already run Redis/Postgres locally, use:
./run-yjs-hub.sh --no-dockerThe bundled yjs-hub demo is ephemeral by default (no persistence across server restarts).
It now also requires a shared websocket token. This FastAPI example passes it via
collaboration.tokenEnv (YHUB_AUTH_TOKEN) and defaults to YOUR_PRIVATE_TOKEN.
This serves websocket rooms at:
ws://127.0.0.1:8081/v1/collaboration/:documentId
If you want a different token value, set this env var before starting:
export YHUB_AUTH_TOKEN="my-demo-token"cd <repo-root>
pnpm dev:collabIf you use Option B, update main.py to point back to that server URL.
cd examples/editor/collaboration/backends/fastapi
uvicorn main:app --reload --port 8000curl "http://127.0.0.1:8000/status"
curl "http://127.0.0.1:8000/insert?text=hello%20world"GET /returns open result + collab config.GET /statusreturns current document/session status.GET /insert?text=...inserts text into the live collaborative doc.GET /markdownextracts the document content as Markdown and renders it in the browser.GET /downloadexports the current session as.docxand downloads it.