The best practice for managing credentials and sensitive configuration data is by fetching them from environment variables
First step: create a config.py
file.
# inside the config.py
from os import environ
SOME_SECRET = environ.get("SOME_SECRET", "YOUR DEFAULT VALUE")
Second step: Make flask to refer to that file to extract its configuration from it.
# indide app.py
app.config.from_pyfile("config.py", silent=False)
Third step: Use these values inside your app.
from flask import current_app
def do_something():
current_app.config.get('SOME_SECRET', None)
...
...
Make sure you are using this code inside your application context
Forth step: Now you have to add these environment variables in the machine(s) which (is/are) going to run your code, whether it is on (Heroku, AWS EC2, k8s node, ..etc)
This way you are making sure that you are not exposing any secret credentials or configurations to anyone who can access your codebase even if it was on a public Github repo.