Deployment and hosting
Reflex deployment turns a Python web app into a production frontend and backend, then sends that packaged app to a managed Reflex hosting service or to a connected cloud account. The same CLI also supports direct provider deployment and export for teams that run their own infrastructure. Its main goal is to keep app configuration, authentication, packaging, and post-deploy control in one workflow. Read this with developer workflows, CLI and project workflows, and extensions and custom components for the wider development context.
Hosting models
Reflex separates the place where an app runs from the tools used to prepare and manage it. This lets a team choose managed operations without giving up control of the cloud account that runs the app.
Managed Reflex hosting
Managed hosting runs the app on Reflex Cloud infrastructure. The reflex deploy command uploads the production package and leaves the service to build and run it. The Reflex dashboard and the reflex cloud commands then provide deployment status, logs, history, scaling, secrets, and rollback. See application lifecycle for the broader app state model.
References: docs/…/deploy-quick-start.md• L7-14 docs/…/cloud-providers.md• L1-3 docs/…/app-management.md• L1-3
Connected cloud hosting
An organization can connect a Google Cloud account to Reflex Cloud and use the normal reflex deploy flow. Reflex keeps the deployment lifecycle under management while the app runs in the organization’s Cloud Run project. This path requires the Enterprise tier and can use named GCP connections when an organization has more than one target.
References: docs/…/cloud-providers.md• L1-15 docs/…/cloud-providers.md• L17-31 packages/…/providers.py• L301-335
Self-managed hosting
Self-managed hosting keeps the runtime outside Reflex Cloud. reflex run --env prod serves the frontend and backend on infrastructure chosen by the team, while reflex export produces artifacts for static hosting or a separate backend. A container is another option when the team wants one repeatable runtime image. In these modes, the frontend must be able to reach the public backend address.
References: docs/…/self-hosting.md• L5-15 docs/…/self-hosting.md• L53-63 docs/…/self-hosting.md• L70-92 docs/…/self-hosting.md• L94-112
Hosting CLI workflows
The hosting CLI is the control surface for authentication, project and app selection, deployment, provider choice, and deployment operations. It supports interactive use for local work and explicit identifiers and tokens for automation.
Authentication and project selection
The CLI authenticates through the browser for local use and caches the resulting access token in the local Reflex configuration. A REFLEX_ACCESS_TOKEN value can supply the token from the environment. Non-interactive commands must receive a usable cached or explicit token, so CI jobs should pass a scoped token rather than rely on a browser session.
Projects group hosted apps. A deploy can name a project by ID or name, or use the selected project saved by the CLI. An app can likewise be found by its name or by an app ID stored in deployment configuration. Explicit command values take precedence over saved configuration values.
References: packages/…/cli.py• L27-79 packages/…/hosting.py• L266-310 packages/…/hosting.py• L351-377 packages/…/project.py• L127-187
Managed deployment sequence
The managed workflow resolves the target app and project before it reserves a URL or builds the package. It validates the request, selects the provider, exports the app, submits both artifacts, and then watches the server-side deployment.
The following flow shows how local preparation hands control to the Reflex hosting service.
flowchart LR
A[reflex deploy] --> B[Authenticate and resolve project/app]
B --> C[Choose provider and hosting mode]
C --> D[Reserve hostname and set runtime URLs]
D --> E[Build production frontend and backend]
E --> F[Upload deployment package]
F --> G[Reflex hosting service builds and runs app]
G --> H[CLI and dashboard report status]
After the upload completes, the service continues the deployment even if the local command exits. The CLI prints a dashboard link and a status command so an engineer can follow the build without keeping the local process open.
References: packages/…/cli.py• L448-519 packages/…/cli.py• L741-829 packages/…/cli.py• L844-966 docs/…/deploy-quick-start.md• L47-74
Deployment operations
After a deployment starts, the CLI treats the deployment as a hosted resource rather than as a local process. Engineers can inspect apps and projects, read runtime or build logs, watch status, stop or start an app, add deployment notes, and roll back to a stored deployment image. These actions use the app or deployment identity resolved from the command, configuration, or project context.
References: packages/…/apps.py• L84-165 packages/…/apps.py• L166-234 packages/…/apps.py• L305-384 docs/…/app-management.md• L33-103
Automation workflows
CI uses the same managed deployment contract without prompts. The GitHub Actions workflow supplies a project ID and a deploy token from repository secrets, then passes optional deployment arguments such as the app directory or region. The security scan uses the same non-interactive token pattern and can make a pipeline fail at a selected finding severity before deployment.
References: docs/…/deploy-with-github-actions.md• L55-99 docs/…/security-scan.md• L41-63 packages/…/scan.py• L164-211
Deployment configuration
Deployment configuration gives a repeatable target for local commands and CI jobs. The CLI reads cloud.yml first and can also read the [tool.reflex-cloud] section of pyproject.toml; an optional environment name selects a nested configuration. Command-line values override values loaded from a file.
Configuration scope
The important settings fall into a small set of concerns:
| Concern | Configuration examples | Effect |
|---|---|---|
| App identity | name, appid, description | Selects or creates the hosted app and labels its deployment history. |
| Project target | project, projectname | Places the app in a Reflex project. |
| Runtime capacity | regions, vmtype, strategy | Controls where the app runs, its machine class, and its rollout style on managed hosting. |
| Public access | hostname, envfile | Sets the hosted name and supplies runtime environment values. |
| Provider target | provider, gcp_connection, full_deploy | Chooses Reflex Cloud or connected GCP and controls how the frontend is served. |
| Package needs | packages, include_db | Adds system packages or includes a local SQLite file in the upload. |
The full field reference is in Cloud configuration. Keep deployment intent in the config file when it must be shared across runs, and use command options for one-off or pipeline-specific changes.
References: packages/…/config.py• L124-145 packages/…/config.py• L194-228 packages/…/config.py• L230-321 docs/…/config_file.md• L17-45 docs/…/config_file.md• L47-145
Configuration precedence
The deploy flow first loads the selected configuration file. It fills only missing command values from that file, then resolves the project, app, provider, and deployment settings. This makes an explicit CLI value the strongest setting while leaving other values reusable from the file.
The same rule applies to runtime environment values: when both --envfile and repeated --env options are present, the environment file wins. Secrets should stay in the hosting secret store or a protected CI secret rather than in a committed config file.
References: packages/…/cli.py• L530-584 packages/…/cli.py• L609-617 packages/…/cli.py• L829-842 packages/…/gcp.py• L701-738 docs/…/secrets-environment-vars.md• L19-30 docs/…/secrets-environment-vars.md• L41-55
Application packaging
Packaging converts the app into a production form that a hosting target can build and run. The frontend is compiled into static web assets and the backend is collected as Python application code. Managed deployment keeps these parts together as one deployment request so the service can start a matching frontend and backend.
Production export
reflex export can create a frontend archive, a backend archive, or both. It can also leave the output unpacked for a host that manages its own file layout. The export process compiles the app in production mode before it creates the artifacts, and it can include or exclude a local database according to the selected options.
References: reflex/reflex.py• L553-620 reflex/…/export.py• L19-46 reflex/…/export.py• L63-102 docs/…/self-hosting.md• L70-92
Hosted deployment package
The managed CLI exports the backend first and the frontend second into a temporary directory. It uploads the resulting backend.zip and frontend.zip with deployment metadata such as the Reflex and Python versions. The hosting service then owns the build and rollout, so the temporary package is a handoff rather than the runtime itself.
References: packages/…/cli.py• L844-908 packages/…/hosting.py• L1873-1979
Runtime URLs and paths
The production frontend must know where to send state events and other backend requests. api_url identifies that public backend address, while deploy_url identifies the frontend address used for generated absolute links. When a reverse proxy serves either side under a subpath, backend_path and frontend_path add the matching route prefixes to the generated URLs.
This relationship is important for both managed and self-managed hosting. A correct package can still appear broken when the browser cannot reach the backend or when a proxy does not pass WebSocket upgrade traffic.
References: packages/…/config.py• L152-189 packages/…/config.py• L195-213 docs/…/self-hosting.md• L11-51 docs/…/self-hosting.md• L65-68
Provider integrations
Provider selection controls where the hosted runtime is created and which operational features remain available. The CLI hides provider-specific wire details behind user-facing names and keeps the app’s selected provider for later deployments.
Managed provider selection
Reflex Cloud is the default managed target. When GCP is connected and allowed for the organization, an interactive deploy offers Reflex Cloud or GCP; a non-interactive job must use --provider or a saved provider setting. A named --gcp-connection selects one usable organization connection by name or ID and never silently falls back to another connection when the name is wrong.
For managed GCP, the connected account supplies the region. The app’s machine type still provides the requested sizing input, which the service maps to the target runtime. Logs, history, scaling, and rollback remain part of the managed lifecycle on both targets.
References: packages/…/cli.py• L82-129 packages/…/cli.py• L160-260 packages/…/cli.py• L741-771 docs/…/cloud-providers.md• L33-73
Hosting mode selection
On managed GCP, the optional full-deploy mode serves the compiled frontend from the GCP runtime instead of Reflex’s CDN. It is an Enterprise-only GCP feature. The mode must be chosen before the hostname is reserved because the frontend is built against that hosting arrangement, and changing it stops a running app before the next deploy brings it back.
References: packages/…/cli.py• L337-412 packages/…/cli.py• L785-819 docs/…/config_file.md• L230-246
Provider switching
An app remembers its provider between deployments. Switching a deployed app tears down resources on the old provider before the new deployment starts, so the CLI warns and asks for confirmation in interactive mode. If a later step fails, it makes a best-effort attempt to restore the former provider; the app still needs an operator to check its state and recover if that restore fails.
References: packages/…/hosting.py• L1031-1083 packages/…/cli.py• L243-305 docs/…/cloud-providers.md• L58-73
Standalone GCP deployment
The standalone GCP workflow uses reflex cloud gcp-standalone to deploy directly to Cloud Run with the user’s local gcloud credentials. Reflex supplies a deployment manifest, while the local CLI prepares the Cloud Build submission and runs the provider script. This workflow is separate from managed GCP: Reflex Cloud does not create an app record or provide its dashboard, logs, rollback, or managed teardown for the result.
References: packages/…/gcp.py• L1-18 packages/…/gcp.py• L243-277 docs/…/deploy-to-gcp.md• L5-19 docs/…/deploy-to-gcp.md• L37-57
Reflex hosting service interaction
The CLI is a client of the Reflex hosting control plane. It validates access, searches for the target project or app, sends deployment metadata and archives, and polls for the resulting state. The service supplies the hosted URL and continues the build after the upload phase.
Control-plane contract
Authenticated requests use the Reflex access token and a hosting service URL. The service validates the token before protected actions, then accepts app, project, provider, capacity, environment, and package data for a deployment. The CLI converts server errors into messages for local users and exposes JSON output where automation needs a machine-readable result.
References: packages/…/hosting.py• L416-467 packages/…/hosting.py• L588-612 packages/…/hosting.py• L1817-1870 packages/…/hosting.py• L1932-1979
Deployment state and recovery
The hosting service owns deployment progress after submission. The CLI can watch that state and fetch build or runtime logs. A successful deployment becomes the current version, while prior compatible images remain candidates for rollback. Provider and hosting-mode changes can affect rollback eligibility because old images may not match the new runtime target.
References: packages/…/apps.py• L166-234 packages/…/apps.py• L305-384 docs/…/app-management.md• L37-77
Hosted secrets
Environment values can enter a managed deployment through a local environment file or explicit CLI values. After deployment, hosted app secrets can be managed in Reflex Build and can optionally restart the app so new values take effect. App-level values override project-level values, and sensitive values should use the protected secret path rather than plain deployment output.
References: packages/…/hosting.py• L1425-1534 docs/…/secrets-environment-vars.md• L9-30 docs/…/secrets-environment-vars.md• L41-72
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
reflex deployoption set,Configfields, config-file examples, and provider aliases aligned. A mismatch can silently select an old saved value or reject a valid deployment target. - Preserve the frontend/backend archive names and the metadata expected by the hosting submission contract. A packaging change affects both the local export flow and the hosting service upload.
- Update URL reservation, hosting mode, and export order together. The frontend is compiled against the selected provider and reserved host.
- Keep managed GCP connection lookup distinct from standalone GCP credentials. The managed path needs an organization connection; the standalone path needs local cloud tools and has no hosted app record.
- Review non-interactive token behavior whenever authentication changes. CI must not depend on browser login or an unscoped local token.
- Treat changes to the provider-switch and failure-recovery rules as lifecycle changes. A failed switch can leave resources torn down or an app stopped even when no new deployment exists.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A non-interactive command has no valid token | The command exits before it can query or change hosted resources. | Pass an explicit scoped token or provide the supported environment token. |
cloud.yml or [tool.reflex-cloud] contains an invalid field or value | Deployment configuration is rejected before the target is built. | Use the defined config fields and validate the selected environment profile. |
| The deployment upload exceeds the service payload limit | The hosting service rejects the deployment and no new version starts. | Remove large files and build artifacts from the project upload. |
| A named GCP connection cannot be read or does not match | The CLI stops rather than deploying to an unintended GCP project. | List connections first and pass the exact connection name or ID. |
| Managed GCP is selected without an allowed connected account | The provider cannot create the runtime. | Check reflex cloud providers status and organization plan access. |
Standalone GCP lacks gcloud, Docker, Bash, or active credentials | The local build or Cloud Run deployment cannot start. | Install the tools and authenticate both the user and application-default accounts. |
The frontend is exported with an unreachable api_url or an incomplete proxy WebSocket setup | The page loads but cannot establish interactive backend state. | Set the public backend URL and pass WebSocket upgrade traffic through the proxy. |
| A provider or full-deploy switch fails after the old runtime is torn down | The app can remain down or need manual recovery. | Confirm destructive changes and inspect the dashboard after a failed switch or mode change. |
Key files
| File | Why to read it |
|---|---|
| packages/…/cli.py | Shows the managed deployment lifecycle from configuration and provider resolution through export, upload, and status watching. |
| packages/…/config.py | Defines the deployment configuration model and how YAML, TOML, and environment profiles are selected. |
| packages/…/hosting.py | Defines the client-side boundary with authentication, project/app lookup, deployment submission, provider state, and hosted secrets. |
| packages/…/gcp.py | Shows the standalone GCP path and its separation from managed Reflex hosting. |
| packages/…/providers.py | Shows how connected provider accounts and GCP deployment readiness are exposed to engineers. |
| reflex/…/export.py | Shows the production export contract used to create deployable frontend and backend artifacts. |
| reflex/reflex.py | Shows the public run and export CLI behavior for production and self-managed hosting. |
| packages/…/config.py | Defines the runtime URL and path settings that connect the built frontend to the backend. |
| docs/…/cloud-providers.md | Explains the user-facing difference between managed Reflex Cloud and managed GCP. |
| docs/…/self-hosting.md | Explains how exported artifacts, public backend URLs, proxies, and containers support self-managed hosting. |