For AI agents: the complete documentation index is at llms.txt. Remove the trailing slash from a page URL and append .md to read its Markdown version. For the docs home, use index.md.

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 run

See the configuration docs for a guided overview of the most commonly tweaked settings.

Fields

app_name

strREFLEX_APP_NAME

The name of the app (should match the name of the app directory).

app_module_import

Optional[str]

Default: None

REFLEX_APP_MODULE_IMPORT

The path to the app module.

loglevel

LogLevel

Default: <LogLevel.DEFAULT: 'default'>

REFLEX_LOGLEVEL

The log level to use.

frontend_port

Optional[int]

Default: 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

Default: ''

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]

Default: 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

Default: ''

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 reflex run restart — routes are registered at startup.

api_url

str

Default: '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]

Default: '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

Default: '0.0.0.0'

REFLEX_BACKEND_HOST

The url the backend will be hosted on.

db_url

Optional[str]

Default: None

REFLEX_DB_URL

The database url used by rx.Model.

async_db_url

Optional[str]

Default: None

REFLEX_ASYNC_DB_URL

The async database url used by rx.Model.

redis_url

Optional[str]

Default: None

REFLEX_REDIS_URL

The redis url.

telemetry_enabled

bool

Default: True

REFLEX_TELEMETRY_ENABLED

Telemetry opt-in.

bun_path

Path

Default: PosixPath('/home/runner/.local/share/reflex/bun/bin/bun')

REFLEX_BUN_PATH

The bun path.

frozen_lockfile

bool

Default: True

REFLEX_FROZEN_LOCKFILE

Run frontend package manager in lockfile-enforcing mode (only honored by bun).

static_page_generation_timeout

int

Default: 60

REFLEX_STATIC_PAGE_GENERATION_TIMEOUT

Timeout to do a production build of a frontend page.

cors_allowed_origins

Sequence[str]

Default: ('*',)

REFLEX_CORS_ALLOWED_ORIGINS

Comma separated list of origins that are allowed to connect to the backend API.

vite_allowed_hosts

bool | list[str]

Default: 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

Default: 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]

Default: []

REFLEX_FRONTEND_PACKAGES

Additional frontend packages to install.

frontend_lazy_bundled_libraries

bool

Default: 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

Default: <StateManagerMode.DISK: 'disk'>

REFLEX_STATE_MANAGER_MODE

Indicate which type of state manager to use.

redis_lock_expiration

int

Default: 10000

REFLEX_REDIS_LOCK_EXPIRATION

Maximum expiration lock time for redis state manager.

redis_lock_warning_threshold

int

Default: 1000

REFLEX_REDIS_LOCK_WARNING_THRESHOLD

Maximum lock time before warning for redis state manager.

redis_token_expiration

int

Default: 3600

REFLEX_REDIS_TOKEN_EXPIRATION

Token expiration time for redis state manager.

env_file

Optional[str]

Default: 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

Default: False

REFLEX_STATE_AUTO_SETTERS

Whether to automatically create setters for state base vars.

default_color_mode

Literal["system", "light", "dark"]

Default: '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 color_mode_cond without requiring a radix theme.

show_built_with_reflex

Optional[bool]

Default: None

REFLEX_SHOW_BUILT_WITH_REFLEX

Whether to display the sticky "Built with Reflex" badge on all pages.

is_reflex_cloud

bool

Default: False

REFLEX_IS_REFLEX_CLOUD

Whether the app is running in the reflex cloud environment.

extra_overlay_function

Optional[str]

Default: None

REFLEX_EXTRA_OVERLAY_FUNCTION

Extra 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_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 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_PLUGINS

List of plugins to use in the app.

disable_plugins

list[type[Plugin]]

Default: []

REFLEX_DISABLE_PLUGINS

List of plugin types to disable in the app.

transport

Literal["websocket", "polling"]

Default: 'websocket'

REFLEX_TRANSPORT

The 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() -> str

Get the config as a JSON string.

Returns

The config as a JSON string.

prepend_frontend_path

prepend_frontend_path(path: str) -> str

Prepend 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) -> str

Prepend 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() -> str

Get the path that the backend Websocket server lists on.

Returns

The namespace for websocket.