Environment Variables

This documentation is for Dash Enterprise.
Dash Enterprise is the fastest way to write & deploy Dash apps and
Jupyter notebooks.
10% of the Fortune 500 uses Dash Enterprise to productionize AI and
data science apps. Find out if your company is using Dash Enterprise.

Environment variables are config values that affect the way your app behaves. They are helpful
for situations when you need your app to behave differently depending on the environment. For example,
you might want your app to use one database when running in a certain environment, and a different database otherwise.

Dash Enterprise provides a way for you to set environment variables in your app’s Settings. Environment variables that you set
this way are used by your app at runtime.

See also: Setting environment variables for your app to use at build time using a project.toml file.

By entering the environment variable name and value in Dash Enterprise, your app can use it without storing the value in code.
We recommend storing sensitive information like API keys as environment variables.
Because the key is not hardcoded in your app’s code, you don’t run the risk of mistakenly exposing or sharing it.

This page describes how to manage environment variables using the App Manager, but you can also use the Dash Enterprise CLI.

System Environment Variables

The following environment variables are created automatically by the system.

```
web: GUNICORN_CMD_ARGS=”–limit-request-field_size=8190” gunicorn app:server –workers 4

```
Learn more about this flag in the Gunicorn documentation.

Adding Environment Variables

Dash Enterprise automatically restarts your app when you add or edit an environment variable, but this does
not affect your app’s availability.

To add an environment variable to your app:

  1. In the Dash Enterprise App Manager, select the app.
  2. Go to Settings.
  3. Under Environment Variables, select Edit Variables.
  4. Select New Variable.
  5. Enter a name and value for your environment variable.

Dash Enterprise automatically uppercases your environment variable names. If your environment variables names contain more than one
word and you want to separate them, be sure to use underscores. Spaces are not supported.

<img>

In this example, we’ve added credentials for a service using environment variables named SERVICE_USER and SERVICE_PASSWORD.

  1. Select Save. If your app has a running workspace, you are prompted to restart the workspace.

Once added, the values for your environment variables are hidden unless you
select Show Values.

You can now reference your environment variables in your app’s code with the os.environ module:

import os

service_username = os.environ['SERVICE_USER']

If you want to fall back to another value when the variable isn’t in your
environment, use:

import os

service_username = os.environ.get('SERVICE_USER', 'my-default-service-username')

Defining Environment Variables in Your Local Environment

If you’re working locally, the variables won’t be in your environment
unless you define them. You can define them on-the-fly when you run python app.py.
That is, instead of running python app.py, run:

$ SERVICE_USER=admin SERVICE_PASSWORD=my-password python app.py

replacing the example environment variables with the environment variables you want to define.

Alternatively, you can define them for your session with the export command.
For example:

$ export SERVICE_USER=admin
$ export SERVICE_PASSWORD=my-password
$ python app.py

Deleting Environment Variables

Dash Enterprise automatically restarts your app when you delete an environment variable, but this does
not affect your app’s availability.

To remove an environment variable:

  1. Select Edit Variables.
  2. Select the Delete icon next to the environment variable you want to remove. You cannot delete environment variables that were created by the system.

<img>

  1. Select Save. If your app has a running workspace, you are prompted to restart the workspace.