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.
1. Write the app
Section titled “1. Write the app”Create a new, empty folder and save this as app.py in it, or download 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 dyuifrom 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_messageasync 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.
2. Run it
Section titled “2. Run it”pip install dyuidyui run app.pyOpen 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.
3. Let a model answer
Section titled “3. Let a model answer”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:
pip install "dyui[openai]"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):
"""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_messageasync 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 partRun 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.
Start from a template
Section titled “Start from a template”dyui new scaffolds a project with an app.py, a README, a requirements.txt, a .gitignore and, for the model templates, an .env.example:
dyui new my-bot --template nvidia # basic · nvidia · openai · anthropic · langgraphcd my-botCopy .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.
Let a coding agent build it
Section titled “Let a coding agent build it”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.
- How DyUI works: the whole loop on one page.
- Your first LLM bot: custom components, actions and steps.
- Components: everything the model can render.