> For AI agents: the complete documentation index is at [llms.txt](https://reflex.dev/docs/llms.txt). Markdown versions are available by appending `.md` or sending `Accept: text/markdown`.

# 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.

```python
# app.py
import reflex as rx

# Define state and pages
...

app = rx.App(
    # Set global level style.
    style={...},
    # Deprecated legacy shortcut for the Radix Themes plugin.
    theme=rx.theme(accent_color="blue"),
)
```

Attributes:
    theme: Deprecated legacy shortcut for configuring the app-level Radix theme.
    style: The [global style](https://reflex.dev/docs/styling/overview/#global-styles}) for the app.
    stylesheets: A list of URLs to [stylesheets](https://reflex.dev/docs/styling/custom-stylesheets/) to include in the app.
    reset_style: Whether to include CSS reset for margin and padding. Defaults to True.
    app_wraps: 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: Extra app wraps to be applied to the whole app.
    head_components: Components to add to the head of every page.
    sio: The Socket.IO AsyncServer instance.
    html_lang: The language to add to the html root tag of every page.
    html_custom_attrs: Attributes to add to the html root tag of every page.
    enable_state: Whether to enable state for the app. If False, the app will not use state.
    admin_dash: Admin dashboard to view and manage the database.
    frontend_exception_handler: Frontend error handler function.
    backend_exception_handler: Backend error handler function.
    toaster: Put the toast provider in the app wrap.
    api_transformer: Transform the ASGI app before running it.

## Fields

| Prop | Description |
| --- | --- |
| `theme: reflex_base.components.component.Component \| None` | Deprecated legacy shortcut for configuring the app-level Radix theme. |
| `style: dict[str \| type[reflex_base.components.component.BaseComponent] \| collections.abc.Callable \| reflex_base.components.component.ComponentNamespace, typing.Any]` | The [global style](https://reflex.dev/docs/styling/overview/#global-styles}) for the app. |
| `stylesheets: list[str]` | A list of URLs to [stylesheets](https://reflex.dev/docs/styling/custom-stylesheets/) to include in the app. |
| `reset_style: bool` | Whether to include CSS reset for margin and padding. Defaults to True. |
| `app_wraps: dict[tuple[int, str], collections.abc.Callable[[bool], reflex_base.components.component.Component \| None]]` | 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], collections.abc.Callable[[bool], reflex_base.components.component.Component \| None]]` | Extra app wraps to be applied to the whole app. |
| `head_components: list[reflex_base.components.component.Component]` | Components to add to the head of every page. |
| `sio: socketio.async_server.AsyncServer \| None` | The Socket.IO AsyncServer instance. |
| `html_lang: str \| None` | The language to add to the html root tag of every page. |
| `html_custom_attrs: dict[str, str] \| None` | Attributes to add to the html root tag of every page. |
| `enable_state: bool` | Whether to enable state for the app. If False, the app will not use state. |
| `admin_dash: reflex.admin.AdminDash \| None` | Admin dashboard to view and manage the database. |
| `frontend_exception_handler: collections.abc.Callable[[Exception], None]` | Frontend error handler function. |
| `backend_exception_handler: collections.abc.Callable[[Exception], reflex_base.event.EventSpec \| list[reflex_base.event.EventSpec] \| None]` | Backend error handler function. |
| `toaster: reflex_base.components.component.Component \| None` | Put the toast provider in the app wrap. |
| `api_transformer: collections.abc.Sequence[collections.abc.Callable[[collections.abc.Callable[[typing.MutableMapping[str, typing.Any], collections.abc.Callable[[], typing.Awaitable[typing.MutableMapping[str, typing.Any]]], collections.abc.Callable[[typing.MutableMapping[str, typing.Any]], typing.Awaitable[NoneType]]], typing.Awaitable[NoneType]]], collections.abc.Callable[[typing.MutableMapping[str, typing.Any], collections.abc.Callable[[], typing.Awaitable[typing.MutableMapping[str, typing.Any]]], collections.abc.Callable[[typing.MutableMapping[str, typing.Any]], typing.Awaitable[NoneType]]], typing.Awaitable[NoneType]]] \| starlette.applications.Starlette] \| collections.abc.Callable[[collections.abc.Callable[[typing.MutableMapping[str, typing.Any], collections.abc.Callable[[], typing.Awaitable[typing.MutableMapping[str, typing.Any]]], collections.abc.Callable[[typing.MutableMapping[str, typing.Any]], typing.Awaitable[NoneType]]], typing.Awaitable[NoneType]]], collections.abc.Callable[[typing.MutableMapping[str, typing.Any], collections.abc.Callable[[], typing.Awaitable[typing.MutableMapping[str, typing.Any]]], collections.abc.Callable[[typing.MutableMapping[str, typing.Any]], typing.Awaitable[NoneType]]], typing.Awaitable[NoneType]]] \| starlette.applications.Starlette \| None` | Transform the ASGI app before running it. |

## Methods

| Signature | Description |
| --- | --- |
| `frontend_exception_handler(exception: 'Exception') -> 'None'` | Default frontend exception handler function. |
| `backend_exception_handler(exception: 'Exception') -> 'EventSpec'` | Default backend exception handler function. |
| `set_contexts(self) -> 'contextlib.AbstractContextManager'` | Set 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(self, component: 'Component \| ComponentCallable \| None' = None, route: 'str \| None' = None, title: 'str \| Var \| None' = None, description: 'str \| Var \| None' = None, image: 'str' = 'favicon.ico', on_load: 'EventType[()] \| None' = None, meta: 'Sequence[Mapping[str, Any] \| Component]' = [], context: 'dict[str, Any] \| None' = 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(self, path: 'str') -> 'list[IndividualEventType[()]]'` | Get the load events for a route. |
| `add_all_routes_endpoint(self)` | Add an endpoint to the app that returns all the routes. |
| `modify_state(self, token: 'BaseStateToken \| str', background: 'bool' = False, previous_dirty_vars: 'dict[str, set[str]] \| None' = None, **context: 'Unpack[StateModificationContext]') -> 'AsyncIterator[BaseState]'` | Modify the state out of band. |
