Heroku Gunicorn Procfile

14,731

Gunicorn takes a flag, --chdir, that lets you select which directory your Python app lives in. So, if you have a directory structure like:

my-project/
  Procfile
  my_folder/
    my_module.py

and my_module.py contains:

app = Flask(__name__, ...)

You can put the following in your Procfile:

web: gunicorn --chdir my_folder my_module:app
Share:
14,731
CasperTN
Author by

CasperTN

Scala and Java Developer

Updated on June 28, 2022

Comments

  • CasperTN
    CasperTN almost 2 years

    I have a hard time finding documentation for creating Procfiles using flask with gunicorn and Heroku. Somewhere I found that the syntax is: web: gunicorn my_folder.my_module:app. But I can't make it work. It only works for me when my python script: hello.py is in the root folder of the app. When I put it in a subfolder called app and create a Procfile: web: gunicorn app.hello:app it doesn't work. Only when I use web: gunicorn hello:app and my python script is in the root folder. Can someone explain me the proper syntax of Procfiles for gunicorn on Heroku, and how to make it work when the python script is in a subfolder?

  • Espoir Murhabazi
    Espoir Murhabazi over 6 years
    your comment save me for many hours of debugging ! kudos can you explained well how my_module:app works?
  • obscurerichard
    obscurerichard over 6 years
    Expanded my answer.
  • Gerardsson
    Gerardsson almost 4 years
    web: gunicorn app:app The first app represents the name of the python file that runs your application or the name of the module it is in. The second app represents the app name that is named in your .py file. Just wanted to add because it helps clarify the contents of the procfile and it's syntax. E.g. your appname would be my_awesome_app in the following code: if __name__ == '__main__': my_awesome_app.run()
  • Biswajit Roy
    Biswajit Roy over 2 years
    Do we have a provision to add the port number here as well? Example: web: gunicorn wsgi:app port:8080