API Reference





To be able to deploy your app, we ask that you prepare a requirements.txt file containing all the required Python packages for it. The hosting service runs a pip install command based on this file to prepare the instances that run your app. We recommend that you use a Python virtual environment when starting a new app, and only install the necessary packages. This reduces the preparation time installing no more packages than needed, and your app is deployed faster. There are a lot of resources online on Python virtual environment tools and how to capture the packages in a requirements.txt file.

When deploying to Reflex's hosting service, the command prompt asks if you want to add any environment variables. These are encrypted and safely stored. We recommend that backend API keys or secrets are entered as envs. Make sure to enter the envs without any quotation marks.

The environment variables are key value pairs. We do not show the values of them in any CLI commands, only their names (or keys). However, if your app intentionally prints the values of these variables, the logs returned still contain the printed values. At the moment, the logs are not censored for anything resembling secrets. Only the app owner and Reflex team admins can access these logs.

You access the values of envs by referencing os.environ with their names as keys in your app's backend. For example, if you set an env ASYNC_DB_URL, you are able to access it by os.environ["ASYNC_DB_URL"]. Some Python libraries automatically look for certain environment variables. For example, OPENAI_API_KEY for the openai python client. The boto3 client credentials can be configured by setting AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY. This information is typically available in the documentation of the Python packages you use.

To redeploy or update your app, navigate to the project directory and type reflex deploy again. This command communicates with the hosting service to automatically detects your existing app by the same name. This time the deploy command overwrites the app. You should see a prompt similar to Overwrite deployment [ app-name ] .... This operation is a complete overwrite and not an incremental update.

All the reflex commands come with a help manual. The help manual lists additional command options that may be useful. You type --help to see the help manual. Some commands are organized under a subcommands series. Here is an example below. Note that the help manual may look different depending on the version of reflex or the reflex-hosting-cli.

reflex deployments --help
Usage: reflex deployments [OPTIONS] COMMAND [ARGS]...

  Subcommands for managing the Deployments.

  --help  Show this message and exit.

  build-logs  Get the build logs for a deployment.
  delete      Delete a hosted instance.
  list        List all the hosted deployments of the authenticated user.
  logs        Get the logs for a deployment.
  regions     List all the regions of the hosting service.
  status      Check the status of a deployment.

When you type the reflex login command for the very first time, it opens the hosting service login page in your browser. We authenticate users through OAuth. At the moment the supported OAuth providers are Github and Gmail. You should be able to revoke such authorization on your Github and Google account settings page. We do not log into your Github or Gmail account. OAuth authorization provides us your email address and in case of Github your username handle. We use those to create an account for you. The email used in the original account creation is used to identify you as a user. If you have authenticated using different emails, those create separate accounts. To switch to another account, first log out using the reflex logout command. More details on the logout command are in reflex logout section.

reflex login
Opening ...
Successfully logged in.

After authentication, the browser redirects to the original hosting service login page. It shows that you have logged in. Now you can return to the terminal where you type the login command. It should print a message such as Successfully logged in.

Your access token is cached locally in the reflex support directory. For subsequent login commands, the cached token is validated first. If the token is still valid, the CLI command simply shows You’re already logged in. If the token is expired or simply not valid for any reason, the login command tries to open your browser again for web based authentication.

When you successfully authenticate with the hosting service, there is information cached in two different places: a file containing the access token in the reflex support directory, and cookies in your browser. The cookies include the access token, a refresh token, some unix epochs indicating when the access token expires. The logout command removes the cached information from these places.

This is the command to deploy a reflex app from its top level app directory. This directory contains a where you run reflex init and reflex run.

A requirements.txt file is required. The deploy command checks the content of this file against the top level packages installed in your current Python environment. If the command detects new packages in your Python environment, or newer versions of the same packages, it prints the difference and asks if you would like to update your requirements.txt. Make sure you double check the suggested updates. This functionality is added in more recent versions of the hosting CLI package reflex-hosting-cli>=0.1.3.

reflex deploy
Info: The requirements.txt may need to be updated.
--- requirements.txt
+++ new_requirements.txt
@@ -1,3 +1,3 @@

Would you like to update requirements.txt based on the changes above? [y/n]: y

Choose a name for your deployed app (https://<picked-name>
Enter to use default. (webui-gray-sun): demo-chat
Region to deploy to. See regions:
Enter to use default. (sjc): lax
Environment variables for your production App ...
 * env-1 name (enter to skip): OPENAI_API_KEY
   env-1 value: sk-*********************
 * env-2 name (enter to skip):
Finished adding envs.
──────────────── Compiling production app and preparing for export. ────────────────
Zipping Backend: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 12/12 0:00:00
Uploading Backend code and sending request ...
Backend deployment will start shortly.
──────────────── Compiling production app and preparing for export. ────────────────
Compiling: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 9/9 0:00:00
Creating Production Build:  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 9/9 0:00:07
Zipping Frontend: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 20/20 0:00:00
Uploading Frontend code and sending request ...
Frontend deployment will start shortly.
───────────────────────────── Deploying production app. ────────────────────────────
Deployment will start shortly:
Closing this command now will not affect your deployment.
Waiting for server to report progress ...
2024-01-12 12:24:54.188271 PST | Updating frontend...
2024-01-12 12:24:55.074264 PST | Frontend updated!
2024-01-12 12:24:55.137679 PST | Deploy success (frontend)
2024-01-12 12:24:59.722384 PST | Updating backend...
2024-01-12 12:25:01.006386 PST | Building backend image...
2024-01-12 12:26:03.672379 PST | Deploying backend image...
2024-01-12 12:26:21.017946 PST | Backend updated!
2024-01-12 12:26:21.018003 PST | Deploy success (backend)
Waiting for the new deployment to come up
Your site [ demo-chat ] at ['lax'] is up:

The deploy command is by default interactive. To deploy without interaction, add --no-interactive and set the relevant command options as deployment settings. Type reflex deploy --help to see the help manual for explanations on each option. The deploy sequences are the same, whether the deploy command is interactive or not.

reflex deploy --no-interactive -k todo -r sjc -r sea --env OPENAI_API_KEY=YOU-KEY-NO-EXTRA-QUOTES --env DB_URL=YOUR-EXTERNAL-DB-URI --env KEY3=THATS-ALOTOF-KEYS

List all your deployments.

reflex deployments list
key                           regions  app_name              reflex_version       cpus     memory_mb  url                                         envs
----------------------------  -------  --------------------  ----------------  -------   -----------  ------------------------------------------  ---------
webui-navy-star               ['sjc']  webui                 0.3.7                   1          1024          ['OPENAI_API_KEY']
chatroom-teal-ocean           ['ewr']  chatroom              0.3.2                   1          1024      []
sales-navy-moon               ['phx']  sales                 0.3.4                   1          1024          []
simple-background-tasks       ['yul']  lorem_stream          0.3.7                   1          1024  []
snakegame                     ['sjc']  snakegame             0.3.3                   1          1024                []
basic-crud-navy-apple         ['dfw']  basic_crud            0.3.8                   1          1024    []

Get the status of a specific app, including backend and frontend.

reflex deployments status clock-gray-piano
Getting status for [ clock-gray-piano ] ...

backend_url                                reachable    updated_at
-----------------------------------------  -----------  ------------  False        N/A

frontend_url                               reachable    updated_at
-----------------------------------------  -----------  -----------------------        True         2023-10-13 15:23:07 PDT

Get the logs from a specific deployment.

The returned logs are the messages printed to console. If you have print statements in your code, they show up in these logs. By default, the logs command return the latest 100 lines of logs and continue to stream any new lines.

We have added more options to this command including from and to timestamps and the limit on how many lines of logs to fetch. Accepted timestamp formats include the ISO 8601 format, unix epoch and relative timestamp. A relative timestamp is some time units ago from now. The units are d (day), h (hour), m (minute), s (second). For example, --from 3d --to 4h queries from 3 days ago up to 4 hours ago. For the exact syntax in the version of CLI you use, refer to the help manual.

reflex deployments logs todo
Note: there is a few seconds delay for logs to be available.
2023-10-13 22:18:39.696028 | rxh-dev-todo | info | Pulling container image
2023-10-13 22:18:41.462929 | rxh-dev-todo | info | Pulling container image
2023-10-13 22:18:45.963840 | rxh-dev-todo | info | Successfully prepared image (4.500906837s)
2023-10-13 22:18:46.134860 | rxh-dev-todo | info | Successfully prepared image (6.438815793s)
2023-10-13 22:18:46.210583 | rxh-dev-todo | info | Configuring firecracker
2023-10-13 22:18:46.434645 | rxh-dev-todo | info | [    0.042971] Spectre V2 : WARNING: Unprivileged eBPF is enabled with eIBRS on, data leaks possible via Spectre v2 BHB attacks!
2023-10-13 22:18:46.477693 | rxh-dev-todo | info | [    0.054250] PCI: Fatal: No config space access function found
2023-10-13 22:18:46.664016 | rxh-dev-todo | info | Configuring firecracker

Get the logs of the hosting service deploying the app.

reflex deployments build-logs webcam-demo
Note: there is a few seconds delay for logs to be available.
2024-01-08 11:02:46.109785 PST | fly-controller-prod | #8 extracting sha256:bd9ddc54bea929a22b334e73e026d4136e5b73f5cc29942896c72e4ece69b13d 0.0s done | None | None
2024-01-08 11:02:46.109811 PST | fly-controller-prod | #8 DONE 5.3s | None | None
2024-01-08 11:02:46.109834 PST | fly-controller-prod |  | None | None
2024-01-08 11:02:46.109859 PST | fly-controller-prod | #8 [1/4] FROM | None | None
2024-01-08 11:02:50.913748 PST | fly-controller-prod | #11 [4/4] RUN . /home/reflexuser/venv/bin/activate && pip install --no-color --no-cache-dir -q -r /home/reflexuser/app/requirements.txt reflex==0.3.4 | None | None
2024-01-08 11:03:07.430922 PST | fly-controller-prod | #12 pushing layer sha256:d9212ef47485c9f363f105a05657936394354038a5ae5ce03c6025f7f8d2d425 3.5s done | None | None
2024-01-08 11:03:07.881471 PST | fly-controller-prod | #12 pushing layer sha256:ee46d14ae1959b0cacda828e5c4c1debe32c9c4c5139fb670cde66975a70c019 3.9s done | None | None
2024-01-08 11:03:13.943166 PST | fly-controller-prod | Built backend image | None | None
2024-01-08 11:03:13.943174 PST | fly-controller-prod | Deploying backend image... | None | None
2024-01-08 11:03:13.943311 PST | fly-controller-prod | Running sys_run | None | None
2024-01-08 11:03:31.005887 PST | fly-controller-prod | Checking for valid image digest to be deployed to machines... | None | None
2024-01-08 11:03:31.005893 PST | fly-controller-prod | Running sys_run | None | None
2024-01-08 11:03:32.411762 PST | fly-controller-prod | Backend updated! | None | None
2024-01-08 11:03:32.481276 PST | fly-controller-prod | Deploy success (backend) | None | None

The hosting service prints log messages when preparing and deploying your app. These log messages are called build logs. Build logs are useful in troubleshooting deploy failures. For example, if there is a package numpz==1.26.3 (supposed to be numpy) in the requirements.txt, hosting service will be unable to install it. That package does not exist. We expect to find a few lines in the build logs indicating that the pip install command fails.

Delete a specific deployment.

These commands do not require authentication.

List all the valid regions to select for a deployment.

Region CodeRegion
altAtlanta, Georgia (US)
bogBogotá, Colombia
bosBoston, Massachusetts (US)
cdgParis, France
denDenver, Colorado (US)
dfwDallas, Texas (US)
ezeEzeiza, Argentina
fraFrankfurt, Germany
hkgHong Kong, Hong Kong
iadAshburn, Virginia (US)
laxLos Angeles, California (US)
lhrLondon, United Kingdom
madMadrid, Spain
miaMiami, Florida (US)
ordChicago, Illinois (US)
sclSantiago, Chile
seaSeattle, Washington (US)
sinSingapore, Singapore
sjcSan Jose, California (US)
sydSydney, Australia
wawWarsaw, Poland
yulMontréal, Canada
yyzToronto, Canada
← Deploy Quick StartSelf Hosting →

Did you find this useful?