Skip to main content

A dynamic-UI layer for any LangGraph agent: emit live UI cards from any node or tool, with any LLM.

Project description

dyui

A dynamic-UI layer for any LangGraph agent. Emit rich, live UI "cards" from inside any LangGraph node or tool — with any LLM, or none — and render them on the frontend with the companion @dyui/react package.

DyUI rides LangGraph's first-class custom stream channel, so it is transport-, model-, and framework-agnostic. No voice, no vendor lock-in.

Install

pip install dyui            # core (langgraph + pydantic)
pip install "dyui[server]"  # + FastAPI SSE server

Emit cards from your agent

from dyui import emit, ui_tool, Card

# 1. Imperative — call anywhere inside a node:
emit("table", {"columns": ["city", "temp"], "rows": [["Berlin", 21]]},
     title="Weather", icon="cloud", accent="cyan")

# 2. Decorator — auto pending -> done/error around a tool:
@ui_tool("stat", title="Sum", icon="plus", accent="emerald")
def add(a: float, b: float) -> dict:
    return {"label": f"{a} + {b}", "value": a + b}

# 3. Context manager — long-running work, one card updated in place:
with Card("progress", title="Indexing") as card:
    for i in range(1, 4):
        card.progress({"value": i, "max": 3})
    card.done({"value": 3, "max": 3, "label": "Done"})

Each event carries an id (auto or yours), a component key (which card to render), props (the data), a status (pending/active/done/error), and an optional surface (which screen region hosts it).

Zero frontend: serve a UI from Python

You don't need React or npm to get a working screen. create_dyui_app hosts a built-in single-file UI at GET / that renders every built-in card and your raw HTML cards:

from dyui.server import create_dyui_app

app = create_dyui_app(my_compiled_graph)   # uvicorn my_module:app --port 8008
# open http://localhost:8008  -> a live dynamic-UI screen, no frontend code

Use your own HTML files as cards

Drop .html templates in a folder and emit them by name — placeholders are filled from props ({{ key }} escaped, {{{ key }}} raw):

from dyui import HtmlTemplates

cards = HtmlTemplates("cards")             # ./cards/invoice.html, weather.html, ...

def my_node(state):
    cards.emit("invoice",
               {"number": 42, "total": "$1,200", "customer": "Acme"},
               title="Invoice", accent="emerald")

That's the whole "one Python file + HTML templates → dynamic UI" path. See examples/html_agent.py and examples/cards/.

The served UI renders the built-in card types and html cards. Bespoke React card components live in @dyui/react; for the no-frontend path, model custom cards as HTML templates instead.

Connect a React frontend (optional)

POST /dyui/stream is a plain SSE endpoint the @dyui/react useDyUIAgent hook consumes directly. Or mount onto an existing app:

from dyui.server import add_dyui_routes
add_dyui_routes(existing_fastapi_app, my_graph, path="/agent/stream")

Test / consume without HTTP

from dyui import collect_events
for ev in collect_events(my_graph, {"query": "berlin"}):
    print(ev["status"], ev["component"], ev["props"])

Built-in card components (frontend)

text, markdown, table, stat, progress, list, keyvalue, json, alert, image, and html (sanitized custom markup). Register your own React components for any component key to fully customise — see the React package.

Development

python -m venv .venv && . .venv/Scripts/activate   # Windows
pip install -e ".[dev]"
pytest

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

dyui-0.1.0.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

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

dyui-0.1.0-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file dyui-0.1.0.tar.gz.

File metadata

  • Download URL: dyui-0.1.0.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for dyui-0.1.0.tar.gz
Algorithm Hash digest
SHA256 036b8a9e0302e4cc312eb379bcb7d52983634d33e9b755a887c4180bd7b9f9bf
MD5 82ebfc2eb9a5fbecf2352d48c9d94652
BLAKE2b-256 5b45f89edf6ba114d4cc28f50b0903ecdeb9a2e334da37601063f5ff688df973

See more details on using hashes here.

File details

Details for the file dyui-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dyui-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for dyui-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e63835008a7d31987ef6eef9ce71897a0593f59ace5b36c09ee03b6209aed916
MD5 3fa922e77cf84733bd8f609ac8b47f6e
BLAKE2b-256 70601953b862547115cba6c7838c3d7ad9b35f6d0772834b74e4594f62b07940

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