Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Command line variables with gunicorn

This is not really a Dash question, but is there an easy way to initialize global variables in the module containing the Dash app, if I run it through gunicorn?

For example, I would like to provide the password to the database when I start the application via a command line argument, and store this password in a global variable in the module.

This sort of thing is commonly done with environment variables:

In your shell or in a bash script before running the app:

export DB_PASSWORD='somepassword'

Within your app:

import os
db_password = os.getenv('DB_PASSWORD)
assert DB_PASSWORD is not None

This is not gunicorn specific, but can be used to pass arbitrary information into your app.

1 Like