Config
reflex_base.config.Config
Configuration class for Reflex applications.
The config defines runtime settings for your app including server ports, database connections, frontend packages, and deployment settings.
By default, the config is defined in an rxconfig.py file in the root of your app:
# rxconfig.py
import reflex as rx
config = rx.Config(
app_name="myapp",
# Server configuration
frontend_port=3000,
backend_port=8000,
# Database
db_url="postgresql://user:pass@localhost:5432/mydb",
# Additional frontend packages
frontend_packages=["react-icons"],
# CORS settings for production
cors_allowed_origins=["https://mydomain.com"],
)Environment Variable Overrides
Any config value can be overridden by setting an environment variable with the REFLEX_
prefix and the parameter name in uppercase:
REFLEX_DB_URL="postgresql://user:pass@localhost/db" reflex run
REFLEX_FRONTEND_PORT=3001 reflex runSee the configuration docs for a guided overview of the most commonly tweaked settings.
Fields
app_name
strREFLEX_APP_NAMEThe name of the app (should match the name of the app directory).
app_module_import
Optional[str]Default: None
REFLEX_APP_MODULE_IMPORTThe path to the app module.
loglevel
LogLevelDefault: <LogLevel.DEFAULT: 'default'>
REFLEX_LOGLEVELThe log level to use.
frontend_port
Optional[int]Default: None
REFLEX_FRONTEND_PORTThe port to run the frontend on. NOTE: When running in dev mode, the next available port will be used if this is taken.
frontend_path
strDefault: ''
REFLEX_FRONTEND_PATHThe path to run the frontend on. For example, "/app" will run the frontend on http://localhost:3000/app
backend_port
Optional[int]Default: None
REFLEX_BACKEND_PORTThe port to run the backend on. NOTE: When running in dev mode, the next available port will be used if this is taken.
backend_path
strDefault: ''
REFLEX_BACKEND_PATHThe path prefix for backend routes. For example, "/api" mounts the event websocket, /ping, /_upload, /_health, and /_all_routes under /api, and is automatically included in URLs baked into the frontend. Changing this requires a full reflex run restart — routes are registered at startup.
api_url
strDefault: 'http://localhost:8000'
REFLEX_API_URLThe backend url the frontend will connect to. Only needs to be set when the backend is listening on a different address than the frontend.
deploy_url
Optional[str]Default: 'http://localhost:3000'
REFLEX_DEPLOY_URLThe url the frontend will be hosted on. Used to build absolute frontend URLs, e.g. links in the generated sitemap.xml.
backend_host
strDefault: '0.0.0.0'
REFLEX_BACKEND_HOSTThe url the backend will be hosted on.
db_url
Optional[str]Default: None
REFLEX_DB_URLThe database url used by rx.Model.
async_db_url
Optional[str]Default: None
REFLEX_ASYNC_DB_URLThe async database url used by rx.Model.
redis_url
Optional[str]Default: None
REFLEX_REDIS_URLThe redis url.
telemetry_enabled
boolDefault: True
REFLEX_TELEMETRY_ENABLEDTelemetry opt-in.
bun_path
PathDefault: PosixPath('/home/runner/.local/share/reflex/bun/bin/bun')
REFLEX_BUN_PATHThe bun path.
frozen_lockfile
boolDefault: True
REFLEX_FROZEN_LOCKFILERun frontend package manager in lockfile-enforcing mode (only honored by bun).
static_page_generation_timeout
intDefault: 60
REFLEX_STATIC_PAGE_GENERATION_TIMEOUTTimeout to do a production build of a frontend page.
cors_allowed_origins
Sequence[str]Default: ('*',)
REFLEX_CORS_ALLOWED_ORIGINSComma separated list of origins that are allowed to connect to the backend API.
vite_allowed_hosts
bool | list[str]Default: False
REFLEX_VITE_ALLOWED_HOSTSAllowed hosts for the Vite dev server. Set to True to allow all hosts, or provide a list of hostnames (e.g. ["myservice.local"]) to allow specific ones. Prevents 403 errors in Docker, Codespaces, reverse proxies, etc.
react_strict_mode
boolDefault: True
REFLEX_REACT_STRICT_MODEWhether to use React strict mode.
frontend_compression_formats
list[str]REFLEX_FRONTEND_COMPRESSION_FORMATSPre-compressed frontend asset formats to generate for production builds. Supported values are "gzip", "brotli", and "zstd". Use an empty list to disable build-time pre-compression.
frontend_packages
list[str]Default: []
REFLEX_FRONTEND_PACKAGESAdditional frontend packages to install.
frontend_lazy_bundled_libraries
boolDefault: False
REFLEX_FRONTEND_LAZY_BUNDLED_LIBRARIESLoad optional dynamic-component libraries when a dynamic component is first evaluated, rather than importing their full namespaces on every page. Defaults to False for compatibility with scripts that read window.__reflex directly.
state_manager_mode
StateManagerModeDefault: <StateManagerMode.DISK: 'disk'>
REFLEX_STATE_MANAGER_MODEIndicate which type of state manager to use.
redis_lock_expiration
intDefault: 10000
REFLEX_REDIS_LOCK_EXPIRATIONMaximum expiration lock time for redis state manager.
redis_lock_warning_threshold
intDefault: 1000
REFLEX_REDIS_LOCK_WARNING_THRESHOLDMaximum lock time before warning for redis state manager.
redis_token_expiration
intDefault: 3600
REFLEX_REDIS_TOKEN_EXPIRATIONToken expiration time for redis state manager.
env_file
Optional[str]Default: None
REFLEX_ENV_FILEPath to file containing key-values pairs to load into the environment; Dotenv format. Multiple files may be separated by os.pathsep. Requires the python-dotenv package.
state_auto_setters
boolDefault: False
REFLEX_STATE_AUTO_SETTERSWhether to automatically create setters for state base vars.
default_color_mode
Literal["system", "light", "dark"]Default: 'system'
REFLEX_DEFAULT_COLOR_MODEThe default color mode for the app: "system" (follow the OS preference), "light", or "dark". Applies to the built-in color mode switcher and color_mode_cond without requiring a radix theme.
show_built_with_reflex
Optional[bool]Default: None
REFLEX_SHOW_BUILT_WITH_REFLEXWhether to display the sticky "Built with Reflex" badge on all pages.
is_reflex_cloud
boolDefault: False
REFLEX_IS_REFLEX_CLOUDWhether the app is running in the reflex cloud environment.
extra_overlay_function
Optional[str]Default: None
REFLEX_EXTRA_OVERLAY_FUNCTIONExtra overlay function to run after the app is built. Formatted such that from path_0.path_1... import path[-1], and calling it with no arguments would work. For example, "reflex_components_moment.moment".
hydrate_fallback
Optional[str]Default: None
REFLEX_HYDRATE_FALLBACKFunction returning the component shown while the page is hydrating (React Router's HydrateFallback), used when App.hydrate_fallback is not set. Formatted such that from path_0.path_1... import path[-1], and calling it with no arguments would work. For example, "my_app.components.loading".
plugins
list[Plugin]Default: []
REFLEX_PLUGINSList of plugins to use in the app.
disable_plugins
list[type[Plugin]]Default: []
REFLEX_DISABLE_PLUGINSList of plugin types to disable in the app.
transport
Literal["websocket", "polling"]Default: 'websocket'
REFLEX_TRANSPORTThe transport method for client-server communication.
Methods
class_fields
class_fields() -> set[str]Get the fields of the config class.
Returns
The fields of the config class.
json
json() -> strGet the config as a JSON string.
Returns
The config as a JSON string.
prepend_frontend_path
prepend_frontend_path(path: str) -> strPrepend the frontend path to a given path.
Parameters
path
The path to prepend the frontend path to.
Returns
The path with the frontend path prepended if it begins with a slash, otherwise the original path.
prepend_backend_path
prepend_backend_path(path: str) -> strPrepend the backend path to a given path.
Parameters
path
The path to prepend the backend path to.
Returns
The path with the backend path prepended if it begins with a slash, otherwise the original path.
update_from_env
update_from_env() -> dict[str, Any]Update the config values based on set environment variables. If there is a set env_file, it is loaded first.
Returns
The updated config values.
get_event_namespace
get_event_namespace() -> strGet the path that the backend Websocket server lists on.
Returns
The namespace for websocket.