Initialize a new Reflex app in the given directory.
(
name: str,
template: str | None = None,
ai: bool = False,
agents: bool = False,
)
| 55 | |
| 56 | |
| 57 | def _init( |
| 58 | name: str, |
| 59 | template: str | None = None, |
| 60 | ai: bool = False, |
| 61 | agents: bool = False, |
| 62 | ): |
| 63 | """Initialize a new Reflex app in the given directory.""" |
| 64 | from reflex.utils import exec, frontend_skeleton, prerequisites, templates |
| 65 | |
| 66 | # Show system info |
| 67 | exec.output_system_info() |
| 68 | |
| 69 | if ai: |
| 70 | from reflex.utils.redir import reflex_build_redirect |
| 71 | |
| 72 | reflex_build_redirect() |
| 73 | return |
| 74 | |
| 75 | # Validate the app name. |
| 76 | app_name = prerequisites.validate_app_name(name) |
| 77 | console.rule(f"[bold]Initializing {app_name}") |
| 78 | |
| 79 | # Check prerequisites. |
| 80 | prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME) |
| 81 | prerequisites.initialize_reflex_user_directory() |
| 82 | prerequisites.ensure_reflex_installation_id() |
| 83 | |
| 84 | # Set up the web project. |
| 85 | prerequisites.initialize_frontend_dependencies() |
| 86 | |
| 87 | # Initialize the app. |
| 88 | template = templates.initialize_app(app_name, template) |
| 89 | |
| 90 | # Initialize the .gitignore. |
| 91 | frontend_skeleton.initialize_gitignore() |
| 92 | |
| 93 | # Write or refresh the AGENTS.md for AI coding agents. |
| 94 | if agents: |
| 95 | frontend_skeleton.initialize_agents_md() |
| 96 | |
| 97 | template_msg = f" using the {template} template" if template else "" |
| 98 | if Path(constants.PyprojectToml.FILE).exists(): |
| 99 | needs_user_manual_update = False |
| 100 | next_steps = " Run `uv run reflex run` to start the app." |
| 101 | else: |
| 102 | needs_user_manual_update = frontend_skeleton.initialize_requirements_txt() |
| 103 | next_steps = " Install dependencies from `requirements.txt` with `uv pip install -r requirements.txt` (or your preferred installer) before running `uv run reflex run`." |
| 104 | manual_update = ( |
| 105 | f" Make sure to add `{constants.RequirementsTxt.DEFAULTS_STUB + constants.Reflex.VERSION}` to your requirements.txt file." |
| 106 | if needs_user_manual_update |
| 107 | else "" |
| 108 | ) |
| 109 | |
| 110 | # Finish initializing the app. |
| 111 | console.success(f"Initialized {app_name}{template_msg}.{manual_update}{next_steps}") |
| 112 | |
| 113 | |
| 114 | @cli.command() |