A server page is a Python function that returns blocks. The app shell
(style: app, the default) fetches them from GET /api/pages/{id}/data and
style: app
GET /api/pages/{id}/data
renders them; forms and buttons talk back through POST /api/pages/{id}/action.
POST /api/pages/{id}/action
Both endpoints sit behind the same auth as every other /api/* route.
/api/*
This guide builds a filter page step by step. Each part works on its own.
@aiui.page("channels", title="Channels") on a function that returns
@aiui.page("channels", title="Channels")
aiui.layout([...]) ({"_components": [...]}) makes a page; every helper in
aiui.layout([...])
{"_components": [...]}
aiui (metric, table, tabs, form, ...) is a block, see
aiui
metric
table
tabs
form
Components. aiui.register_page(id, title=..., handler=fn)
aiui.register_page(id, title=..., handler=fn)
does the same without the decorator. Run the app with aiui run app.py.
aiui run app.py
A handler that takes params receives the page URL's query string as a dict.
params
A key given once is a string; a key given more than once is a list:
The handler is matched by its signature: a parameter named params (or
**kwargs) gets it by keyword, a single required positional parameter gets it
**kwargs
positionally, and a handler with no parameters is called as before.
The app shell sends the URL's query string with every data request, so a
filtered view survives a refresh, a bookmark and a shared link. The page's
Refresh button re-fetches with the current params.
aiui.form(action_id, children=[...], submit_label=...) collects every input
aiui.form(action_id, children=[...], submit_label=...)
inside it by name (or by its label when it has no name). Give inputs a
name
name so the keys are stable. The first argument is the action id, normally
the page id.
There are two ways to submit.
The values are written into the page URL (history.replaceState) and the page
history.replaceState
data is fetched again, so the page handler sees them in params. No action
handler is needed. This is the right choice for a filter form:
Render each input with value= taken from params, so the form shows the
value=
active filters after a refresh. An empty value removes its key from the URL;
other keys in the URL stay. Keys starting with _ are never written.
_
The values are POSTed as JSON to /api/pages/{page_id}/action. Handle them
/api/pages/{page_id}/action
with aiui.register_page_action(page_id):
aiui.register_page_action(page_id)
What the reply can hold:
| Key | Effect in the app shell |
|-----|-------------------------|
| _components | Replaces the page with these blocks (return aiui.layout([...])). |
_components
| message (or status) | A success toast. With _components, both happen. |
message
status
| error | An error toast; the page is left as it was. |
error
| _params | Written into the page URL's query string (aiui.layout([...], params={...})); None or "" removes a key. |
_params
aiui.layout([...], params={...})
None
""
| _refresh_every | Starts or changes auto refresh (section 5). |
_refresh_every
aiui.form(..., update_url=True) writes the submitted values into the URL
aiui.form(..., update_url=True)
after a successful POST, as method="get" does. Use it when the action both
method="get"
does something and changes the view; a reply's _params wins over it.
A button posts {**payload, "action": action, "_params": {...}}. A form posts
{**payload, "action": action, "_params": {...}}
its values alongside "_params" (the page URL's current query string, same
"_params"
dict shape as params in the page handler).
To stream LLM tokens or step-by-step progress live without polling, make your
@aiui.register_page_action handler an async def (or sync) generator that
@aiui.register_page_action
async def
yields aiui.layout([...]) frames:
yield
The server streams each yielded frame as application/x-ndjson; the app shell
application/x-ndjson
updates the page live and displays a Stop button to cancel the stream.
Heavy sections can load when they are first opened instead of with the page:
lazy=True
children
load value, or its label. An item with children renders at once.
load
label
aiui.expander(title, lazy=True, load=key)
{"_lazy": key, "_params": {...}}. Reply with _components, as for any
{"_lazy": key, "_params": {...}}
action. A reply with error (or an HTTP error) shows the message and a
"Try again" button; a skeleton shows while it loads.
auto refresh, an action that re-renders), open sections fetch again; a
closed one fetches again the next time it opens.
refresh_every (seconds, at least 1) re-fetches the page while its browser
refresh_every
tab is visible. It pauses while the tab is hidden and resumes when it is shown
again. After a failure it keeps the last good content, shows one error toast
and doubles the wait on each failure in a row (up to 5 minutes).
Set it when you register the page, or per reply (a reply's value wins, so a
page can refresh only while something runs):
@aiui.page(..., refresh_every=10) and
@aiui.page(..., refresh_every=10)
aiui.register_page(..., refresh_every=10) set a fixed period; the data
aiui.register_page(..., refresh_every=10)
reply carries it as _refresh_every unless the handler set that key.
@aiui.page(..., badge=...) and aiui.register_page(..., badge=...) show a
@aiui.page(..., badge=...)
aiui.register_page(..., badge=...)
short pill beside the page title in the app shell sidebar (across Classic and
all selectable layouts). Pass a string, an integer, or a zero-argument callable
(evaluated when the manifest is served) for live counts such as unread items or
queued jobs. To update badges dynamically after an action without reloading the
page, return aiui.layout([...], badges={"inbox": 2}) (or refresh_manifest=True).
aiui.layout([...], badges={"inbox": 2})
refresh_manifest=True
aiui run app.yaml can declare server-driven block pages directly in YAML
aiui run app.yaml
(alongside built-in page ids such as chat):
chat
Every component block (card, metric, table, chart, gallery,
card
chart
gallery
card_grid, filter_bar, select_input, list_detail, markdown_text,
card_grid
filter_bar
select_input
list_detail
markdown_text
doc_viewer, pagination, color_picker_input, …) uses the same JSON/YAML
doc_viewer
pagination
color_picker_input
dict format as Python's aiui.* helpers. Large apps can split page definitions
aiui.*
into separate files with $ref: (e.g. - $ref: ./pages/overview.yaml). Edits
$ref:
- $ref: ./pages/overview.yaml
to the YAML file, any $ref-included file, or a referenced markdown_file
$ref
markdown_file
reload dynamically on the next fetch without restarting the server. Set
api_endpoint: instead of components: to back a YAML-declared page with a
api_endpoint:
components:
custom API or plugin endpoint.
The app shell supports everything in this guide. The legacy dashboard
dashboard
style renders the page and its forms. It ignores params, method="get",
lazy loading and refresh_every, and shows a status as plain text.