Reflex Hosting CLI
The `reflex-hosting-cli` is a command-line interface tool designed to streamline the deployment of Reflex web applications to the Reflex hosting service. It provides commands for logging into the hosting platform and deploying projects with ease. Currently at version 0.1.62, it is under active development, often receiving updates in sync with the core Reflex framework.
Common errors
-
Command 'rx-host' not found
cause The `reflex-hosting-cli` is not installed or its executable `rx-host` is not in your system's PATH.fixEnsure you have installed the package correctly with `pip install reflex-hosting-cli`. If installed, verify your PATH environment variable includes the directory where pip installs scripts (e.g., `~/.local/bin` on Linux/macOS, `Scripts` directory in Python installation on Windows). -
Authentication Failed: Invalid credentials or token expired.
cause Your login session has expired, or the provided credentials for `rx-host login` were incorrect.fixRun `rx-host login` again in your terminal to re-authenticate and obtain a new token. -
Error: No Reflex project found in the current directory.
cause The `rx-host deploy` command was executed from a directory that does not contain a valid Reflex project (i.e., it's missing the `rxconfig.py` file or other project structure).fixNavigate into the root directory of your Reflex project (the directory containing `rxconfig.py`) before running `rx-host deploy`.
Warnings
- breaking The `reflex-hosting-cli` version must be compatible with your installed `reflex` framework version. Mismatched versions can lead to deployment failures or unexpected behavior.
- gotcha Authentication is required before deploying. You must log in to the Reflex hosting service using `rx-host login`.
- gotcha The CLI is under active development, and commands, options, or behavior might change between minor versions.
Install
-
pip install reflex-hosting-cli
Imports
- Config
from reflex_hosting_cli.config import Config
Quickstart
import subprocess
import os
import sys
# This quickstart demonstrates the typical command-line flow for
# deploying a Reflex application using reflex-hosting-cli.
# It requires 'reflex' and 'reflex-hosting-cli' to be installed.
project_name = "my_quickstart_app"
# Ensure we start clean for the quickstart
if os.path.exists(project_name):
print(f"Removing existing project '{project_name}' for a clean start...")
subprocess.run(["rm", "-rf", project_name], check=True)
try:
print(f"1. Initializing a new Reflex project: '{project_name}'...")
# This command uses the 'reflex' CLI, a prerequisite.
subprocess.run(["reflex", "init", project_name], check=True, capture_output=True, text=True)
print(f" Project '{project_name}' initialized.")
os.chdir(project_name)
print("\n2. Logging into Reflex Hosting (requires manual interaction or pre-configured token)...")
print(" Please run 'rx-host login' in your terminal and follow prompts.")
print(" For this quickstart, we assume you are already logged in or will log in interactively.")
# You would typically run: `subprocess.run(["rx-host", "login"], check=True)`
# This is commented out as it requires interactive input.
print("\n3. Deploying the Reflex project...")
print(" Note: This command requires active Reflex hosting credentials.")
# Using --yes to skip interactive confirmation if possible.
# check=False because actual deployment success depends on external factors (account, network, etc.)
# and we want the quickstart script itself to complete without error due to failed deployment.
result = subprocess.run(["rx-host", "deploy", "--yes"], capture_output=True, text=True)
print(" Deployment command output:")
print(result.stdout)
if result.stderr:
print(" Deployment command errors:")
print(result.stderr)
print("\n Deployment command finished. Check the output above for status.")
except FileNotFoundError as e:
print(f"\nError: Command '{e.filename}' not found. Please ensure 'reflex' and 'reflex-hosting-cli' are installed and in your system's PATH.", file=sys.stderr)
print("Install with: pip install reflex reflex-hosting-cli", file=sys.stderr)
except subprocess.CalledProcessError as e:
print(f"\nAn error occurred during command execution: {e}", file=sys.stderr)
print(f"STDOUT:\n{e.stdout}", file=sys.stderr)
print(f"STDERR:\n{e.stderr}", file=sys.stderr)
finally:
# Always try to clean up
if os.path.basename(os.getcwd()) == project_name:
os.chdir("..")
if os.path.exists(project_name):
print(f"\nCleaning up project directory '{project_name}'...")
subprocess.run(["rm", "-rf", project_name], check=True)