Reflex Hosting CLI

0.1.62 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the typical workflow for deploying a Reflex application using the `reflex-hosting-cli`. It initializes a new Reflex project, then attempts to deploy it. Note that `rx-host login` needs to be run interactively to authenticate with the Reflex hosting service before deployment, or environment variables must be configured.

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)

view raw JSON →