This documentation is for Dash Enterprise.
Dash Enterprise is the fastest way to write & deploy Dash apps and
10% of the Fortune 500 uses Dash Enterprise to productionize AI and
data science apps. Find out if your company is using Dash Enterprise.
This page applies to Dash Enterprise 5. If your organization uses Dash Enterprise 4, view information about environment variables at
Environment variables are config values that affect the way your Dash 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. 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.
The following environment variables are created automatically by the system.
created automatically when you create an app. These environment variables are used by Dash when you construct paths using
app.get_asset_url. You don’t need to reference them anywhere in your code.
GIT_REV is created automatically the first time you update your code and stores your app’s latest Git revision.
It’s the long-form version of the git revision displayed in your app Overview. You can use this environment variable in conjunction with
to enable advanced functionalities like persisting the cache across redeploys and invalidating it when the app’s source changes.
Learn more in Background Callback Caching.
DATABASE_URL are created automatically when you add a managed Redis or Postgres database to your app,
respectively. You’ll need to reference these environment variables in your code for your app to use these databases. Learn more in
Redis and Postgres.
DASH_ENTERPRISE_ENV is created automatically with the value
WORKSPACE when you create a workspace for your app.
It is present only in the workspace environment, allowing you to set workspace-specific behavior. Dash Enterprise does not use
DASH_ENTERPRISE_ENV when deploying your app, so it does not appear in your app’s Environment Variables settings.
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:
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.
In this example, we’ve added credentials for a service using environment variables named
Known issue: We are aware of an issue where selecting Restart Workspace in the Workspace Restart Required message does not restart the workspace. To have access to environment variables in your workspace, restart the workspace from the Workspace tab.
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
import os service_username = os.environ['SERVICE_USER']
If you want to fall back to another value when the variable isn’t in your
import os service_username = os.environ.get('SERVICE_USER', 'my-default-service-username')
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
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 SERVICE_USER=admin $ export SERVICE_PASSWORD=my-password $ python app.py
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: