Hi @funza Welcome and thanks for reaching out!
Great question! The
app.config.from_envvar function will look for a file path inside of the environment variable that you provide and try to read your variables from that file. We recommend against storing secrets on your filesystem so we have a different approach.
This example takes in your configuration as environment variables and assigns them to Flask’s configuration via
from flask import Flask
from os import environ as env
app = Flask(__name__)
app.config["SERVER_NAME"] = env["SERVER_NAME"]
# String (Mapped Name)
app.config["SECRET_KEY"] = env["FLASK_SECRET_KEY"]
app.config["TESTING"] = env["TESTING"] == "true"
app.config["NUM_WORKERS"] = int(env["NUM_WORKERS"])
This approach allows you to handle type conversion as well as mapping names in Doppler to known configuration variables in Flask.
To pass environment variables to your application, you can use
# Using `flask run`
doppler run -- flask run
# Using gunicorn
doppler run -- gunicorn app:app
Keep in mind that the ENV Flask configuration variable is automatically set by the FLASK_ENV environment variable.
Here are some additional resources on using environment variables in Python and on Flask’s configuration object.
Please let me know if you have any questions!