Config
reflex_base.config.ConfigConfiguration 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
| Prop | Environment Variable | Description |
|---|---|---|
app_name: str | REFLEX_APP_NAME | The name of the app (should match the name of the app directory). |
app_module_import: Optional[str] = None | REFLEX_APP_MODULE_IMPORT | The path to the app module. |
loglevel: LogLevel = <LogLevel.DEFAULT: 'default'> | REFLEX_LOGLEVEL | The log level to use. |
frontend_port: Optional[int] = None | REFLEX_FRONTEND_PORT | The 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: str = '' | REFLEX_FRONTEND_PATH | The path to run the frontend on. For example, "/app" will run the frontend on http://localhost:3000/app |
backend_port: Optional[int] = None | REFLEX_BACKEND_PORT | The 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: str = '' | REFLEX_BACKEND_PATH | The 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 |
api_url: str = 'http://localhost:8000' | REFLEX_API_URL | The 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] = 'http://localhost:3000' | REFLEX_DEPLOY_URL | The url the frontend will be hosted on. Used to build absolute frontend URLs, e.g. links in the generated sitemap.xml. |
backend_host: str = '0.0.0.0' | REFLEX_BACKEND_HOST | The url the backend will be hosted on. |
db_url: Optional[str] = None | REFLEX_DB_URL | The database url used by rx.Model. |
async_db_url: Optional[str] = None | REFLEX_ASYNC_DB_URL | The async database url used by rx.Model. |
redis_url: Optional[str] = None | REFLEX_REDIS_URL | The redis url. |
telemetry_enabled: bool = True | REFLEX_TELEMETRY_ENABLED | Telemetry opt-in. |
bun_path: Path = PosixPath('/home/runner/.local/share/reflex/bun/bin/bun') | REFLEX_BUN_PATH | The bun path. |
frozen_lockfile: bool = True | REFLEX_FROZEN_LOCKFILE | Run frontend package manager in lockfile-enforcing mode (only honored by bun). |
static_page_generation_timeout: int = 60 | REFLEX_STATIC_PAGE_GENERATION_TIMEOUT | Timeout to do a production build of a frontend page. |
cors_allowed_origins: Sequence[str] = ('*',) | REFLEX_CORS_ALLOWED_ORIGINS | Comma separated list of origins that are allowed to connect to the backend API. |
vite_allowed_hosts: bool | list[str] = False | REFLEX_VITE_ALLOWED_HOSTS | Allowed 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: bool = True | REFLEX_REACT_STRICT_MODE | Whether to use React strict mode. |
frontend_compression_formats: list[str] | REFLEX_FRONTEND_COMPRESSION_FORMATS | Pre-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] = [] | REFLEX_FRONTEND_PACKAGES | Additional frontend packages to install. |
frontend_lazy_bundled_libraries: bool = False | REFLEX_FRONTEND_LAZY_BUNDLED_LIBRARIES | Load 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: StateManagerMode = <StateManagerMode.DISK: 'disk'> | REFLEX_STATE_MANAGER_MODE | Indicate which type of state manager to use. |
redis_lock_expiration: int = 10000 | REFLEX_REDIS_LOCK_EXPIRATION | Maximum expiration lock time for redis state manager. |
redis_lock_warning_threshold: int = 1000 | REFLEX_REDIS_LOCK_WARNING_THRESHOLD | Maximum lock time before warning for redis state manager. |
redis_token_expiration: int = 3600 | REFLEX_REDIS_TOKEN_EXPIRATION | Token expiration time for redis state manager. |
env_file: Optional[str] = None | REFLEX_ENV_FILE | Path 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: bool = False | REFLEX_STATE_AUTO_SETTERS | Whether to automatically create setters for state base vars. |
default_color_mode: Literal["system", "light", "dark"] = 'system' | REFLEX_DEFAULT_COLOR_MODE | The default color mode for the app: "system" (follow the OS preference), "light", or "dark". Applies to the built-in color mode switcher and |
show_built_with_reflex: Optional[bool] = None | REFLEX_SHOW_BUILT_WITH_REFLEX | Whether to display the sticky "Built with Reflex" badge on all pages. |
is_reflex_cloud: bool = False | REFLEX_IS_REFLEX_CLOUD | Whether the app is running in the reflex cloud environment. |
extra_overlay_function: Optional[str] = None | REFLEX_EXTRA_OVERLAY_FUNCTION | Extra overlay function to run after the app is built. Formatted such that |
hydrate_fallback: Optional[str] = None | REFLEX_HYDRATE_FALLBACK | Function returning the component shown while the page is hydrating (React Router's HydrateFallback), used when App.hydrate_fallback is not set. Formatted such that |
plugins: list[Plugin] = [] | REFLEX_PLUGINS | List of plugins to use in the app. |
disable_plugins: list[type[Plugin]] = [] | REFLEX_DISABLE_PLUGINS | List of plugin types to disable in the app. |
transport: Literal["websocket", "polling"] = 'websocket' | REFLEX_TRANSPORT | The transport method for client-server communication. |
Methods
| Signature | Description |
|---|---|
class_fields() -> set[str] | Get the fields of the config class. |
json() -> str | Get the config as a JSON string. |
prepend_frontend_path(path: str) -> str | Prepend the frontend path to a given path. |
prepend_backend_path(path: str) -> str | Prepend the backend path to a given path. |
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. |
get_event_namespace() -> str | Get the path that the backend Websocket server lists on. |