Reflex Logo

Intro

Gallery

Hosting

Components

New

Learn

Components

API Reference

Onboarding

Api-reference

/

App

reflex.app.App

A Reflex application.

FieldDescription
FieldDescription
pages A map from a page route to the component to render.
stylesheets A list of URLs to stylesheets to include in the app.
api The backend API object.
sio The Socket.IO AsyncServer.
socket_app The socket app.
state The state class to use for the app.
style The styling to apply to each component.
middleware Middleware to add to the app.
load_events List of event handlers to trigger when a page loads.
admin_dash Admin dashboard
event_namespace The async server name space
head_components Components to add to the head of every page.
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.
overlay_component A component that is present on every page.
background_tasks Background tasks that are currently running
theme The radix theme for the entire app
SignatureDescription
__init__(self, *args, **kwargs)Initialize the app.
enable_state(self) -> 'None'Enable state for the app.
setup_state(self) -> 'None'Set up the state for the app.
__repr__(self) -> 'str'Get the string representation of the app.
__call__(self) -> 'FastAPI'Run the backend api instance.
add_default_endpoints(self)Add default api endpoints (ping).
add_optional_endpoints(self)Add optional api endpoints (_upload).
add_cors(self)Add CORS middleware to the app.
preprocess(self, state: 'BaseState', event: 'Event') -> 'StateUpdate | None'Preprocess the event. This is where middleware can modify the event before it is processed. Each middleware is called in the order it was added to the app. If a middleware returns an update, the event is not processed and the update is returned.
postprocess(self, state: 'BaseState', event: 'Event', update: 'StateUpdate') -> 'StateUpdate'Postprocess the event. This is where middleware can modify the delta after it is processed. Each middleware is called in the order it was added to the app.
add_middleware(self, middleware: 'Middleware', index: 'int | None' = None)Add middleware to the app.
_generate_component(component: 'Component | ComponentCallable') -> 'Component'Generate a component from a callable.
add_page(self, component: 'Component | ComponentCallable', route: 'str | None' = None, title: 'str | None' = None, description: 'str | None' = None, image: 'str' = 'favicon.ico', on_load: 'EventHandler | EventSpec | list[EventHandler | EventSpec] | None' = None, meta: 'list[dict[str, str]]' = [], script_tags: 'list[Component] | 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, route: 'str') -> 'list[EventHandler | EventSpec]'Get the load events for a route.
_check_routes_conflict(self, new_route: 'str')Verify if there is any conflict between the new route and any existing route. Based on conflicts that NextJS would throw if not intercepted. Raises: ValueError: exception showing which conflict exist with the route to be added
add_custom_404_page(self, component: 'Component | ComponentCallable | None' = None, title: 'str' = '404 - Not Found', image: 'str' = 'favicon.ico', description: 'str' = 'The page was not found', on_load: 'EventHandler | EventSpec | list[EventHandler | EventSpec] | None' = None, meta: 'list[dict[str, str]]' = [])Define a custom 404 page for any url having no match. If there is no page defined on 'index' route, add the 404 page to it. If there is no global catchall defined, add the 404 page with a catchall
setup_admin_dash(self)Setup the admin dash.
get_frontend_packages(self, imports: 'Dict[str, set[ImportVar]]')Gets the frontend packages to be installed and filters out the unnecessary ones.
_should_compile(self) -> 'bool'Check if the app should be compiled.
_setup_overlay_component(self)If a State is not used and no overlay_component is specified, do not render the connection modal.
compile(self)compile_() is the new function for performing compilation. Reflex framework will call it automatically as needed.
_apply_decorated_pages(self)Add @rx.page decorated pages to the app. This has to be done in the MainThread for py38 and py39 compatibility, so the decorated pages are added to the app before the app is compiled (in a thread) to workaround REF-2172. This can move back into `compile_` when py39 support is dropped.
compile_(self, export: 'bool' = False)Compile the app and output it to the pages folder.
modify_state(self, token: 'str') -> 'AsyncIterator[BaseState]'Modify the state out of band.
_process_background(self, state: 'BaseState', event: 'Event') -> 'asyncio.Task | None'Process an event in the background and emit updates as they arrive.

Did you find this useful?