Heroku: Run a Python App Locally

Author: Jacek Trociński, Last Revision: 2020.11.12, Topic area: Heroku

Heroku has a built in command that allows you to run a Python app locally using the Heroku config variables that are defined for your app. The config variable values can be changed to meet the needs of your local environment.

Start by exporting your app's configuration variables using Git Bash (in order for the file to have the right encoding) to a .env file then edit the .env variable values for local use if local and production values differ.

heroku config -s > .env

Next, exclude the .env file from you Git repository by placing it in the .gitignore file.

Lastly, make sure you have a Procfile defined so that you can run your app locally using the command:

heroku local