Skip to content

App

class App(
title: str = 'DyUI',
*,
description: Optional[str] = None,
welcome: Optional[str] = None,
placeholder: str = 'Message {title}…',
logo: Optional[str] = None,
theme: Literal['system', 'light', 'dark'] = 'system',
accent: str = 'indigo',
starters: Sequence[Union[str, Starter]] = (),
components: Union[Literal['all'], Sequence[Union[str, type[Component]]], None] = 'all',
persist: Any = True,
password: Optional[str] = None,
uploads: bool = True,
feedback: bool = True,
history: bool = True,
max_upload_mb: int = 20,
data_dir: Union[str, Path, None] = None,
embed_origins: Sequence[str] = (),
csp: Union[bool, str] = True,
)

A DyUI chat application (and an ASGI app: uvicorn app:app works).

Parameters

Name Type Description
title str App name, shown in the header and browser tab.
description Optional[str] Shown under the welcome heading.
welcome Optional[str] Welcome heading (default “How can I help?”).
placeholder str Composer placeholder; {title} is substituted.
logo Optional[str] URL or local image path for your logo.
theme Literal['system', 'light', 'dark'] "system", "light" or "dark".
accent str indigo (default), teal, rose, amber, emerald, slate or a hex color.
starters Sequence[Union[str, Starter]] Suggested first messages (strings or dyui.Starter).
components Union[Literal['all'], Sequence[Union[str, type[Component]]], None] Which built-in components the LLM may use: "all", a list of names / component classes, or None for none. Custom components are always included.
persist Any True → SQLite at ./.dyui/dyui.db; a path → SQLite there; False → in memory; or a Store instance.
password Optional[str] Require this shared password to use the app.
uploads bool Allow file uploads.
feedback bool Show thumbs up/down on replies.
history bool Show the conversation sidebar.
max_upload_mb int Upload size limit.
data_dir Union[str, Path, None] Where DyUI keeps its database and uploads (default ./.dyui).
embed_origins Sequence[str] Sites allowed to show this app in an <iframe> (e.g. ["https://example.com"]). By default only the app itself may frame it.
csp Union[bool, str] The Content-Security-Policy sent with the app’s HTML: True (DyUI’s strict default), a policy string of your own, or False to send none.
def on_message(fn: Handler) -> Handler

Register the reply handler: (msg: Message, chat: Chat). Required.

def on_chat_start(fn: Handler) -> Handler

Register a handler run when a conversation starts: (chat: Chat).

def on_feedback(fn: Handler) -> Handler

Register a thumbs up/down handler: (feedback: Feedback, chat: Chat).

def on_action(name: str) -> Callable[[Handler], Handler]

Register a handler for a component action: (action: Action, chat: Chat).

It may yield a reply like on_message. Unhandled actions are sent to on_message as an LLM-friendly "[action:name] {...}" message.

def component() -> type[Component]

Register a custom component; the LLM learns it on the next turn.

The components this app’s LLM may use (enabled built-ins + your custom ones).

Rebuilt on every access, so the prompt always reflects the live registry.

Everything this app can render (all built-ins + custom).

What model-written UI may use: every LLM built-in + custom components.

Used for fenced dyui blocks in text and {"ui": ...} dicts (which is what tools-mode LLM calls produce). Developer-only components (html, invalid) are excluded — the LLM can never produce HTML. Developers render ui.Html by yielding the component instance.

async def check_action(user_id: str, req: dict[str, Any]) -> tuple[int, str, Any]

Verify an action request without side effects.

Returns (status, error, data): status is 0 when the action is valid (data is then the server-side static data to use), else an HTTP status.

def claim_action(req: dict[str, Any]) -> Optional[tuple[str, str]]

Claim a component for one action request (synchronous: call right after check_action, with no await in between).

Returns the claim key, or None if another request already holds it (a concurrent double-click). Released by handle_action once the resolution is recorded; stale claims expire after _CLAIM_TTL_S.

def asgi() -> Any

The underlying FastAPI application (built lazily).

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.