Skip to content

Quickstart

This page builds a bot in a single app.py. The first version needs no API key. It shows how a handler streams text and components into a reply. The second lets a model answer.

Create a new, empty folder and save this as app.py in it, or download app.py:

app.py
"""Weather Desk: a DyUI bot with no model and no API key.
Save as app.py, then run: dyui run app.py
"""
import dyui
from dyui import ui
app = dyui.App(
title="Weather Desk",
description="Ask about the weather in any city.",
starters=["Weather in Lisbon", dyui.Starter("Compare two cities", "Compare Lisbon and Porto", icon="map")],
)
@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
yield f"Here's the outlook for **{msg.text}**."
yield ui.Stats(ui.Stat("Today", "24°C", trend="up", delta="+2°"), ui.Stat("Rain", "10%"))
yield ui.QuickReplies("Tomorrow?", "Compare with Porto")

Paste into an empty file. Pasting below code that’s already there joins the last line of one to the first line of the other, and Python reports a syntax error.

A handler can yield three kinds of value:

  • Strings: streamed into the reply as Markdown.
  • Components (ui.*): rendered inline where they’re yielded.
  • dyui.Reasoning(...): shown as a collapsible “thinking” block.

Handlers can be async generators, sync generators or plain functions. A plain function may return a value or a list of values.

Terminal window
pip install dyui
dyui run app.py

Open http://localhost:8000. dyui run finds app.py, main.py or bot.py when you leave the file out, and reloads the app whenever you save.

You now have:

  • a welcome screen with your starters;
  • a streaming reply with stats and quick replies;
  • a sidebar of past conversations, stored in SQLite at ./.dyui/dyui.db;
  • stop, regenerate, edit, copy, feedback, file uploads, and light and dark themes.

Install the SDK extra and add your key to a .env file next to app.py. NVIDIA’s key is free at build.nvidia.com:

Terminal window
pip install "dyui[openai]"
.env
NVIDIA_API_KEY=nvapi-...

dyui run loads .env for you. To set the key in your shell instead (PowerShell and cmd included), or to use another provider, see API keys & environment.

Then replace app.py with a version whose handler streams a model instead of yielding fixed text (download):

app.py
"""Weather Desk, answered by a model that renders DyUI components.
Needs: pip install "dyui[openai]" and NVIDIA_API_KEY in a .env file next to this one.
Save as app.py, then run: dyui run app.py
"""
import os
import dyui
# Any "provider/model" string works; change it here or with the DYUI_MODEL variable.
MODEL = os.getenv("DYUI_MODEL", "nvidia/moonshotai/kimi-k2.6")
app = dyui.App(
title="Weather Desk",
description="Ask about the weather in any city.",
starters=["Weather in Lisbon", dyui.Starter("Compare two cities", "Compare Lisbon and Porto", icon="map")],
)
@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
async for part in dyui.llm.stream(
MODEL,
chat.history,
system="You are a concise weather assistant.",
components=app.catalog, # teaches the model DyUI's components
):
yield part

Run dyui run app.py again and ask about a city.

The openai extra is the SDK that talks to every OpenAI-compatible endpoint, NVIDIA’s included, which is why it is the one to install here. Any provider/model string works; see Models & providers.

components=app.catalog appends a generated “UI components” section to the system prompt. The model then writes components into its reply, and DyUI parses, validates and renders them while they stream. Generative UI explains how.

dyui new scaffolds a project with an app.py, a README, a requirements.txt, a .gitignore and, for the model templates, an .env.example:

Terminal window
dyui new my-bot --template nvidia # basic · nvidia · openai · anthropic · langgraph
cd my-bot

Copy .env.example to .env (cp .env.example .env on macOS and Linux, copy .env.example .env on Windows), add your key, then run dyui run.

dyui mcp install connects Claude Code, Cursor, VS Code, Codex, Gemini CLI and other coding agents to DyUI’s documentation, component schemas and checks, so they can build the app with you. See Build with AI.

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.