For AI agents: the complete documentation index is at llms.txt. Markdown versions are available by appending .md or sending Accept: text/markdown.
Reflex Logo
Docs Logo
Api Reference

/

App

App

reflex.app.App

The main Reflex app that encapsulates the backend and frontend.

Every Reflex app needs an app defined in its main module.

Fields

PropDescription
theme: Optional[Component] = None

Deprecated legacy shortcut for configuring the app-level Radix theme.

style: dict[str | type[BaseComponent] | Callable | ComponentNamespace, Any] = {}

The global style for the app.

stylesheets: list[str] = []

A list of URLs to stylesheets to include in the app.

reset_style: bool = True

Whether to include CSS reset for margin and padding. Defaults to True.

app_wraps: dict[tuple[int, str], Callable[[bool], Optional[Component]]]

App wraps to be applied to the whole app. Expected to be a dictionary of (order, name) to a function that takes whether the state is enabled and optionally returns a component.

extra_app_wraps: dict[tuple[int, str], Callable[[bool], Optional[Component]]] = {}

Extra app wraps to be applied to the whole app.

head_components: list[Component] = []

Components to add to the head of every page.

sio: Optional[AsyncServer] = None

The Socket.IO AsyncServer instance.

html_lang: Optional[str] = None

The language to add to the html root tag of every page.

html_custom_attrs: Optional[dict[str, str]] = None

Attributes to add to the html root tag of every page.

enable_state: bool = True

Whether to enable state for the app. If False, the app will not use state.

admin_dash: Optional[AdminDash] = None

Admin dashboard to view and manage the database.

frontend_exception_handler: Callable[[Exception], None] = default_frontend_exception_handler

Frontend error handler function.

backend_exception_handler: Callable[[Exception], Optional[EventSpec | list[EventSpec]]] = default_backend_exception_handler

Backend error handler function.

toaster: Optional[Component] = Toaster.create

Put the toast provider in the app wrap.

hydrate_fallback: Optional[Component | Callable[[], Component | tuple[Component, Ellipsis] | str]] = None
api_transformer: Optional[Sequence[Callable[[ASGIApp], ASGIApp] | Starlette] | Callable[[ASGIApp], ASGIApp] | Starlette] = None

One or more transforms applied to the backend ASGI app before it runs — mount a FastAPI/Starlette app or wrap it in ASGI middleware. See the API Transformer docs for examples.

Methods

SignatureDescription
set_contexts() -> AbstractContextManagerSet Reflex contexts needed for state and event processing. Pushes RegistrationContext and EventContext into the current contextvars scope, but only if they are not already set. Can be used as a context manager:: with app.set_contexts(): async with app.modify_state(token) as state: ...
add_page(component: Optional[Component | ComponentCallable] = None, route: Optional[str] = None, title: Optional[str | Var] = None, description: Optional[str | Var] = None, image: str = 'favicon.ico', on_load: Optional[EventType[()]] = None, meta: Sequence[Mapping[str, Any] | Component] = [], context: Optional[dict[str, Any]] = None)Add a page to the app. If the component is a callable, by default the route is the name of the function. Otherwise, a route must be provided.
get_load_events(path: str) -> list[IndividualEventType[()]]Get the load events for a route.
add_all_routes_endpoint()Add an endpoint to the app that returns all the routes.
modify_state(token: BaseStateToken | str, background: bool = False, previous_dirty_vars: Optional[dict[str, set[str]]] = None, **context: Unpack[StateModificationContext]) -> AsyncIterator[BaseState]Modify the state out of band.
Built with Reflex