Using python-dotenv with Dash-based app hosted on Heroku

I’ve got a Dash-based application. This app makes an API call to source data, which in turn is plotted on a dashboard. In order to make this API call, I have an API access token.

For obvious reasons, I’d want to keep the API-Key secret.

This resource tells me how to use python-dotenv to do exactly that with a Flask or Django app.

It says nothing about a Dash-app though. I know, Dash uses Flask in the background but the steps suggested in the above resource do not help me.

Any ideas on this would be appreciated.

In Heroku, you can setup Config Vars (click on Settings tab within your Heroku project). These config vars are then set as environment variables when your app is deployed.

Within your python code, you can access them via the following:


If not already done, you will also need:

import os

Thank you. That worked for me!

1 Like