PrefabApp. It holds your component tree, state, theme, and external assets together as a single unit.
Creating an App
Context manager
The natural way to build an app. Components inside thewith block become the view:
pf-app-root CSS class that themes target for default padding. Add your own classes via css_class:
Passing a view
If you build the tree separately, pass it viaview=:
From wire data
PrefabApp.from_json() wraps pre-serialized wire protocol data, for example from sandboxed execution. Keyword arguments override values from the wire:
Fields
| Field | Type | Description |
|---|---|---|
view | Component | dict | Component tree to render (set automatically in context manager mode) |
state | dict | Initial client-side state |
theme | Theme | Theme to apply — see Themes |
css_class | str | Additional CSS/Tailwind classes for the root container. Stacks on top of pf-app-root. |
defs | list[Define] | Reusable component definitions |
stylesheets | list[str] | CSS URLs or inline CSS to load in <head> |
scripts | list[str] | External JS URLs to load in <head> |
connect_domains | list[str] | Domains to allow in CSP connect-src (for Fetch actions) |
title | str | HTML page title (default: "Prefab") |
Methods
app.html() returns a complete, self-contained HTML page with the Prefab renderer and all data baked in.
app.to_json() returns the wire-format envelope — a dict with $prefab, view, state, defs, and theme.
app.csp() computes Content Security Policy domains from the app’s asset configuration.
State
state sets the initial values that template expressions like {{ count }} resolve against:
PrefabApp constructor:
Stylesheets
Thestylesheets field accepts both URLs and inline CSS. URLs become <link> tags; inline CSS (detected by {) becomes a <style> tag. For theming, prefer theme= over inline stylesheets.