Use this file to discover all available pages before exploring further.
Define captures a component subtree as a named template. Use references it by name, optionally injecting scoped data. The template is defined once and can appear any number of times in the tree with different data.
from prefab_ui.define import Definefrom prefab_ui.use import Usefrom prefab_ui.response import UIResponsefrom prefab_ui.components import Card, CardHeader, CardTitle, CardDescription, Columnwith Define("user-card") as user_card: with Card(): with CardHeader(): CardTitle("{{ name }}") CardDescription("{{ role }}")with Column(gap=3) as view: Use("user-card", name="Alice", role="Engineer") Use("user-card", name="Bob", role="Designer") Use("user-card", name="Carol", role="PM")UIResponse(view=view, defs=[user_card])
Three cards with different data, but the card structure is defined once. The kwargs passed to Use become interpolation values scoped to that instance of the template.
Define uses the context manager like any container, but it does not attach itself to a parent — it lives outside the component tree. Pass it to UIResponse via the defs parameter.
from prefab_ui.define import Definefrom prefab_ui.components import Badge, CardTitle, Rowwith Define("status-row") as status_row: with Row(gap=2, css_class="items-center"): CardTitle("{{ label }}") Badge("{{ status }}", variant="{{ variant }}")
UIResponse(view=layout, defs=[status_row])
If a Define contains multiple children, they’re automatically wrapped in a Column.
Use references a Define by name. Any kwargs that aren’t base component fields (css_class) become scoped interpolation values for the template.
from prefab_ui.use import Use# Bare reference (data comes from surrounding scope)Use("status-row")# With scoped dataUse("status-row", label="Build", status="passing", variant="default")