✨ Announcing our seed funding led by Lux Capital! Read more about it on our blog
DocsBlogChangelog

Search documentation...

/

Star

12k+

[ Learn ]

[ Concepts ]

[ Reference ]

CLI


The reflex command line interface (CLI) is a tool for creating and managing Reflex apps.
To see a list of all available commands, run reflex --help.
$ reflex --help
Usage: reflex [OPTIONS] COMMAND [ARGS]...

Options:
  --help   Show this message and exit.

Commands:
  db       Subcommands for managing the database schema
  deploy   Deploy the app to the Reflex hosting service.
  export   Export the app to a zip file.
  init     Initialize a new Reflex app in the current directory.
  run      Run the app in the current directory.
  version  Get the Reflex version.

Init


The reflex init command creates a new Reflex app in the current directory. If a rxconfig.py file already exists already, it will re-initialize the app with the latest template.
 ~/my_app $ reflex init
[...] Initializing the web directory.                                                                                                                            utils.py:421
[...] Finished Initializing: my_app
~/my_app $ tree
.
├── assets
│   └── favicon.ico
├── my_app
│   ├── __init__.py
│   └── my_app.py
└── rxconfig.py
 

Run


The reflex run command runs the app in the current directory.
By default it runs your app in development mode. This means that the app will automatically reload when you make changes to the code. You can also run in production mode which will create an optimized build of your app.
You can configure the mode, as well as other options through flags.
$ reflex run --help
Usage: reflex run [OPTIONS]

  Run the app in the current directory.

Options:
  --env [dev|prod]                The environment to run the app in.
                                  [default: Env.DEV]
  --frontend-only                 Execute only frontend.
  --backend-only                  Execute only backend.
  --loglevel [debug|info|warning|error|critical]
                                  The log level to use.  [default:
                                  LogLevel.ERROR]
  --frontend-port TEXT            Specify a different frontend port.
  --backend-host TEXT             Specify a different backend host.
  --backend-port TEXT             Specify a different backend port.
  --help                          Show this message and exit.
  

Export


You can export your app's frontend and backend to zip files using the reflex export command.
The frontend is a compiled NextJS app, which can be deployed to a static hosting service like Github Pages or Vercel. However this is just a static build, so you will need to deploy the backend separately. See the self-hosting guide for more information.
$ reflex export --help
Usage: reflex export [OPTIONS]

  Export the app to a zip file.

Options:
  --no-zip         Disable zip for backend and frontend exports.  [default:
                   True]
  --backend-only   Export only backend.
  --frontend-only  Export only frontend.
  --for-reflex-deploy  Whether export the app for Reflex Deploy Service.
  --help           Show this message and exit.
  

DB


The db subcommand is used to manage the database schema using alembic.
$ reflex db --help
Usage: reflex db [OPTIONS] COMMAND [ARGS]...

  Subcommands for managing the database schema

Options:
  --help  Show this message and exit.

Commands:
  init            Create database schema and migration configuration.
  makemigrations  Create autogenerated alembic migration scripts.
  migrate         Create or update database schema based on app models
  

Init


Before the builtin database integration can be used, reflex db init must be called to create the alembic directory and populate the initial schema. If alembic.ini already exists in the project directory, this command will return an error

Make Migrations


When database schema changes are made, reflex db makemigrations is used to generate alembic scripts that can update the database schema to match the model definitions. The scripts are saved in the alembic/versions directory and should be committed to version control.
$ reflex db makemigrations --help
Usage: reflex db makemigrations [OPTIONS]

  Create autogenerated alembic migration scripts.

Options:
  --message TEXT  Human readable identifier for the generated revision.
  --help          Show this message and exit.

Migrate


After migration scripts are generated, the reflex db migrate command applies the changes to the active database (defined in rxconfig.py).
← ScriptEvent Triggers →

Copyright © 2023 Pynecone, Inc.