Components
A component is a single widget on an AdminPage. Every component is registered with a decorator, and every decorator does the same two things: it registers a real FastAPI route, and it records the widget's metadata into the page's spec.
| Component | Decorator | Purpose |
|---|---|---|
| Stat | @page.stat(...) | A single value — a count, a percentage, a boolean |
| Table | @page.table(...) | A paginated, searchable grid with optional per-row actions |
| Form | @page.form(...) | A structured form that submits to your own endpoint |
| Action | @page.action(...) | A one-off button that calls an endpoint |
| Bar Chart | @page.bar_chart(...) | A categorical bar chart |
| Pie Chart | @page.pie_chart(...) | A proportional breakdown chart |
| Markdown | @page.markdown(...) | A static or dynamic rich text block |
| Area Chart | — not yet available | Defined in the spec, no decorator yet |
| Line Chart | — not yet available | Defined in the spec, no decorator yet |
Shared behavior
A few things apply to every component, not just one:
- Parameters are inferred from the function signature.
Query(...),Body(...),Form(...), pydantic models, andDepends(...)all work exactly as they do in any FastAPI route. OpenAdmin walks the resolved dependency tree and turns the query, body, and form parameters into JSON Schema, which becomes part of the component's spec. iconandcoloraccept any value from the sharedIconandColorliteral types inopenadmin.spec(Lucide icon names and Tailwind-style color names, respectively).refresh(onstat,table,markdown,bar_chart,pie_chart) takes adatetime.timedelta. When set, the frontend polls the component's endpoint on that interval.is_hidden(ontable,action,form) registers the endpoint and includes it in the spec, but keeps it out of the visible page layout. This is the mechanism behind row actions and reference fields — see Implementing a Table and Implementing a Form with a Reference.method(onaction,form) is any ofget,post,put,patch,delete,head, and maps directly to the matching FastAPI router method.
Referencing one component from another
Two helpers let one component point at another by its generated ID, instead of hardcoding route paths:
python
from openadmin.fastapi import reference_action, reference_tablereference_table(table_func)— returns the ID of a@page.table(...)-decorated function. Used in a form field'sreferenceto source a value picker from that table's rows.reference_action(action_func)— returns the ID of a@page.action(...)-decorated function. Used in a table row's__actions__to attach that action as a row button.
Both simply read an attribute (__openadmin_table_id__ / __openadmin_action_id__) that the decorator stamped onto the function, so the referenced function must already be decorated — but not necessarily called — before you reference it.