Deploy Python Flask to Heroku

Ryan Lintag
2 min readFeb 12, 2021


Install the Heroku CLI

Download and install the Heroku CLI.

If you haven’t already, log in to your Heroku account and follow the prompts to create a new SSH public key.

$ heroku login


Add the following files to the application’s root folder:


Heroku apps include a Procfile that specifies the commands that are executed by the app on startup.

Add the following line:

web: python

Note: Change the to your startup file.


Pipfile is used to specify the preferred python version and all the dependencies of the application.

Add the following lines:

url = ""
verify_ssl = true
name = "pypi"
flask = "*"
adaboost-model = "0.1.0"
python_version = "3.7"

Note: Make sure to specify the correct python version and include all the required packages of you applicaiton.

Change the host of the flask application to this:

if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))'', port=port)

Generate the Pipfile.lock file using the following command:

$ pipenv lock

Note: Every time you have a changes in the Pipfile, you must run this command.

Create Heroku Application

  1. Login to Heroku site
  2. Go to Heroku dashboard
  3. Click New -> Create new app
  4. Enter the App name
  5. Click Create app button
  6. Go to Settings tab of you app
  7. Click the Add buildpack button
  8. Select buildpack (in this article, choose python)
  9. Click Save changes button


Create a new Git repository

Initialize a git repository in a new or existing directory

$ cd my-project/
$ git init
$ heroku git:remote -a app-name

Note: Change the app-name to your application name from Heroku.

Deploy your application

Commit your code to the repository and deploy it to Heroku using Git.

$ git add .
$ git commit -am "make it better"
$ git push heroku master

Heroku will generate a new link for your application’s public access.