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 build time as well as at runtime.
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 Settings in the App Info, but you can also use the Dash Enterprise CLI.
The following environment variables are created automatically by the system.
DASH_APP_NAME
, DASH_REQUESTS_PATHNAME_PREFIX
, DASH_PATH_ROUTING
, and DASH_ROUTES_PATHNAME_PREFIX
are
created automatically when you create an app. These environment variables are used by Dash when you construct paths using
dash.get_relative_path
, dash.strip_relative_path
, or dash.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 cache_by
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.
REDIS_URL
and 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.
GUNICORN_CMD_ARGS
is created automatically with the value --limit-request-field_size=16384
, which sets the header size limit to 16 KB.
You can override this limit by specifying one in your Procfile
. For example, to set it back to the Gunicorn default of 8 KB:
```
web: GUNICORN_CMD_ARGS=”–limit-request-field_size=8190” gunicorn app:server –workers 4
```
Learn more about this flag in the Gunicorn documentation.
DASH_SECRET_KEY
is created automatically when you create an app. It is used by the system to allow requests that originate from Snapshot Engine background tasks
when the app is protected by dash-enterprise-auth
.
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.
Environment variables for specifying Python and pip versions,
BP_CPYTHON_VERSION
andBP_PIP_VERSION
, can also be set in a project.toml file. When these environment variables are set in both your app Settings and aproject.toml
file, the values in the Settings take precedence.
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.
<img>
In this example, we’ve added credentials for a service using environment variables named SERVICE_USER
and SERVICE_PASSWORD
.
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')
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
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:
<img>