Widgets
Widgets are the building blocks for plugin admin pages. Build a page by passing a list of
widgets to ViewBuilder.generate().
Building a page
from fastpluggy.core.dependency import get_view_builder
@router.get("/my-page", response_class=HTMLResponse)
def my_page(request: Request, view_builder=Depends(get_view_builder)):
return view_builder.generate(
request,
title = "My Page",
widgets = [TableWidget(...), ButtonListWidget(...)],
)
Every other keyword argument of generate() goes into the page's template context. A widget, or a
list or tuple holding one, passed under another keyword (items=, the name used before the
ViewBuilder) raises TypeError instead of rendering an empty page.
Data widgets
TableWidget
Sortable data table from a list of dicts.
from fastpluggy.core.widgets import TableWidget
TableWidget(
data = [{"name": "Alice", "role": "admin"}, ...],
title = "Users",
title_icon = "ti ti-users",
fields = ["name", "role"], # explicit column order
headers = {"name": "Full Name"}, # column label overrides
exclude_fields = ["password"],
field_callbacks = {"role": render_role_badge},# callable(value) → HTML string, kept as markup;
# every other cell prints as text
links = [EditButton(...)], # action buttons per row
sortable = True,
)
Under 768 px each row is shown as a card, each value labelled with its column header.
TableModelWidget
Same as TableWidget but reads columns and rows from a SQLAlchemy model.
TableModelWidget(model=MyModel, title="All records",
default_sort={"column": "created_at", "order": "desc"})
default_sort orders the rows until the user sorts on a column; its arrow shows on that
column from the first render.
The table is paginated: limits (100) is the number of rows per page until the user picks
another one. pagination_options passes window (page links around the current one),
rows_per_page_options (the choices offered) and default_rows_per_page, which wins over
limits when both are given.
TableModelWidget(model=MyModel, limits=25,
pagination_options={"rows_per_page_options": [25, 50, 100]})
ModelWidget
Displays a Pydantic model's fields in a read-only key/value table.
Field names and values print as text (escaped). Like in TableWidget, what a
field_callbacks entry returns is kept as HTML, and so is a value that is markupsafe.Markup.
Cell renderers (RenderFieldTools)
fastpluggy.core.widgets.render_field_tools.RenderFieldTools holds ready-made renderers for
field_callbacks (of TableWidget, TableModelWidget and ModelWidget). Each one escapes the
value it inserts and returns Markup, so a value holding < or & shows as text:
| Renderer | Draws |
|---|---|
render_link(url, label=None, *, new_tab=False) |
a link (below) |
render_status_badge(value, colors=None, ...) |
a status badge of the UI kit |
render_tag(text) |
a tag of the UI kit |
render_boolean(value) |
a Yes / No badge |
render_datetime(value, *, relative=False) |
2026-11-19 10:13:19 UTC (see Database) |
render_relative_datetime(value) |
the age (3h ago) with the full UTC date in the tooltip, — when missing (see Database) |
render_http_verb_badges(verbs) |
one outlined badge per HTTP verb |
render_label_list(values) |
a list as chips |
render_enum(value) |
an enum member as a badge, coloured by the enum's badge_class attribute ("bg-green-lt"), neutral without one; any other value as text |
render_icon(classes) |
an icon from its classes ("ti ti-star") |
render_link escapes the URL and the text. The text defaults to the URL; an empty URL, or one
whose scheme is not relative, http, https or mailto (javascript:...), gives the text alone,
not a link. new_tab=True adds target="_blank" rel="noopener".
from functools import partial
from fastpluggy.core.widgets.render_field_tools import RenderFieldTools
TableWidget(
data=[{"name": "docs", "homepage": "https://example.org/docs", "docs_url": "/docs/1"}],
fields=["name", "homepage"],
field_callbacks={
"homepage": partial(RenderFieldTools.render_link, new_tab=True), # the URL as its text
"name": lambda name, row: RenderFieldTools.render_link(row["docs_url"], name),
},
)
TableWidget calls a callback with (value, row) first: render_link used directly ignores the
row (a mapping given as label). The row holds the cells already rendered by the callbacks before
it, so build a URL from a key no callback renders (docs_url above). A path that is not a page one can open (a route template such as
/items/{item_id}) is shown as text by passing an empty URL:
lambda path: RenderFieldTools.render_link("" if "{" in path else path, path).
DebugWidget
Renders arbitrary data as formatted JSON. Useful during development.
TracebackWidget
Displays a Python traceback list (used automatically in the plugin error panel). Each line prints
as text (#138), so pass the lines as traceback.format_exception() gives them, unescaped.
Input widgets
FormWidget
Auto-generates a form from a Pydantic model. Submits to the current URL via POST. Checkbox fields handle the absent-means-False HTML behavior correctly.
from fastpluggy.core.widgets import FormWidget
FormWidget(
model = MySettings, # class or instance
data = current_settings, # instance with current values
readonly_fields = ["namespace"],
)
SettingsFormWidget
A FormWidget for a pydantic settings class, as the admin's settings pages render it:
groups, switches, units, environment and secret badges, Reset to default, a save bar.
What it reads from each field is in Settings.
SettingsFormWidget(model=MySettings, data=current_settings, action=save_url,
readonly_fields=["namespace"])
editable_fields lists the fields a save may write (neither set by the environment nor
read-only): pass it to save_settings_form(..., form_fields=widget.editable_fields).
ButtonWidget
A single button. Renders as <a> for URL navigation or <form><button> for POST actions.
from fastpluggy.core.widgets.categories.input.button import ButtonWidget
ButtonWidget(label="Export", url="/my/export", css_class="btn btn-secondary")
Parameters shared by every button (BaseButtonWidget):
ButtonWidget(
url = "/some/path",
label = "Click me",
method = "post", # "get" (default) or "post"
css_class = "btn btn-danger btn-sm",
icon = "ti ti-trash",
condition = True, # bool, or callable(item) -> bool
confirm = "Are you sure?", # Bootstrap confirmation modal, no JS needed
params = {"key": "value"}, # hidden form fields of a POST
target = "_blank", # open in a new tab, no JS (see below)
)
A button carries no inline JavaScript: onclick= raises TypeError, since a Content-Security-Policy
without 'unsafe-inline' blocks inline handlers. To run code on click, give the button a
css_class (or render your own widget with data- attributes) and bind the click by delegation in
the plugin's JS file, loaded with extra_js_files:
document.addEventListener('click', (e) => {
const button = e.target.closest('.my-plugin-refresh');
if (!button) return;
e.preventDefault();
fetch(button.href, {method: 'POST'});
});
widgets/input/button.html.j2 renders one of three shapes, in this order:
confirmset: a trigger button plus an inline modal. The modal's action is a<form>for a POST and a link otherwise. Its id (confirm_id) is generated; never set it.method == "post": a<form>withparamsas hidden inputs.- Otherwise, an
<a href>.
Opening in a new tab: target
target sets where the action opens, with no JavaScript: the target attribute of the <a> (GET)
or of the <form> (POST), the confirmation modal's action and the entries of a
DropdownButtonWidget included. The button that opens a confirm modal keeps opening the modal.
from fastpluggy.core.widgets import ButtonWidget, DropdownButtonWidget
DropdownButtonWidget(title="Links", buttons=[
ButtonWidget(label="API docs", url="/docs", icon="ti ti-book", target="_blank"),
ButtonWidget(label="Export CSV", url="/my/export", method="post", target="_blank",
confirm="Export every row?"),
ButtonWidget(label="Logs", url="/my/logs", target="my-plugin-logs"),
])
target |
Renders | Notes |
|---|---|---|
None (default) |
nothing | HTML unchanged |
"_blank" |
target="_blank", plus rel="noopener noreferrer" on a link, rel="noopener" on a form |
a visually hidden "(opens in a new tab)" follows the label for screen readers |
"_self", "_parent", "_top" |
target="…" |
|
a window name ("my-plugin-logs") |
target="…" |
every button naming it reuses that one tab; no rel, which would make each click open a new tab |
The value is checked when the button is built: anything else ("", "_new", "_Blank", a space or
a quote) raises ValueError. It is one string for the widget, the same for every row of a
TableWidget. A form gets no noreferrer: its POST would then send Origin: null, which
same_origin_or_403 refuses. A window name keeps window.opener: use "_blank" for a page of
another site. On a DropdownButtonWidget itself target does nothing; set it on its entries.
AutoLinkWidget
A button that navigates to a named FastAPI route — the URL is resolved from the app's
real route table via url_for, so it always points at something that actually exists.
from fastpluggy.core.widgets.categories.input.button import AutoLinkWidget
AutoLinkWidget(
route_name = "toggle_plugin_status",
label = "Enable",
icon = "ti ti-play me-1",
css_class = "btn btn-primary",
param_inputs = {"plugin_name": plugin_name},
condition = some_bool_or_callable,
confirm = "Sure?",
)
param_inputs values support <field_name> placeholders substituted from the row dict
when the button is used inside a TableWidget via links — or a plain static value, as
in the example above. The route's HTTP method, path/query/body params are inspected
automatically from the FastAPI route named route_name.
There is no endpoint that calls a function from its dotted path: it would let any caller run
any function. To give an action a button, give it its own named route and point an
AutoLinkWidget at it. Return the outcome through handle_action_result()
(core/tools/fastapi.py), which applies the returned flash messages or redirect:
# core/routers/base_module.py
@base_module_router.post("/{plugin_name}/remove", name="remove_plugin_route",
dependencies=[Depends(same_origin_or_403)])
def remove_plugin_route(request: Request, plugin_name: str, fast_pluggy=Depends(get_fastpluggy)):
result = PluginService.remove_plugin(plugin_name=plugin_name, fast_pluggy=fast_pluggy)
return handle_action_result(request, result, endpoint_name="list_plugins")
DropdownButtonWidget
A button that opens a menu of buttons, e.g. the ⋯ of a page header:
from fastpluggy.core.widgets import AutoLinkWidget, DropdownButtonWidget
DropdownButtonWidget(
title="More actions", # tooltip and screen-reader label; no label = icon only
buttons=[
AutoLinkWidget(route_name="reload_fast_pluggy_route", label="Reload plugins", icon="ti ti-refresh"),
AutoLinkWidget(route_name="remove_plugin_route", label="Delete", icon="ti ti-trash",
css_class="btn btn-danger", # danger: red entry
param_inputs={"plugin_name": name},
confirm="Delete it? This cannot be undone."),
],
)
Each entry keeps its condition and confirm; a POST entry is a form in the menu. The button
is not rendered when no entry is left. Give label= to show text with a caret instead of the
ti ti-dots icon.
ButtonListWidget
A collection of buttons with flexible layout options.
from fastpluggy.core.widgets.categories.input.button_list import ButtonListWidget
ButtonListWidget(
buttons = [AutoLinkWidget(...), ButtonWidget(...)],
title = "Actions",
layout = "horizontal", # "horizontal" | "vertical"
style = "list", # "list" (spaced) | "group" (Bootstrap btn-group)
button_size = "md", # "sm" | "md" | "lg"
)
Display widgets
CustomTemplateWidget
Include any Jinja2 template with custom context. The widget variable in the template
holds the widget instance (context keys are also set as attributes on it).
from fastpluggy.core.widgets.categories.display.custom import CustomTemplateWidget
CustomTemplateWidget(
template_name = "my_plugin/my_card.html.j2",
context = {"data": my_data},
)
Like any widget it takes title, title_icon and widget_id: inside a TabbedWidget
they give the tab its label, its icon and its own panel.
TabbedWidget(tabs=[
CustomTemplateWidget(template_name="my_plugin/details.html.j2",
title="Details", title_icon="ti ti-info-circle"),
TableWidget(title="History", ...),
])
Layout widgets
TabbedWidget
Wraps other widgets in a Bootstrap tab interface. None values are filtered out,
so conditional tabs are safe to pass directly.