Using Heroku to keep your Python scripts running 24/7

First let’s talk about what Heroku is

Heroku is a cloud platform as a service supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language, but now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go.

What it can be used for

It can be used to host scripts in the above mentioned supported languages, but this article will be focused on Python instead of the other languages. What Heroku can do is your code running 24/7. You may ask what you would use this for.

Prerequisites needed before beginning the use of Heroku

You will need 3 things:

  1. Git, which is a CLI (Install here)
  2. Create a new app, by clicking on the new icon at the top right.
  3. Heroku CLI, can be installed after creating your app.

An example: hosting a discord bot with Heroku

  1. First, navigate to the directory where your python script is located.
    Open the CLI you usually use in that directory, and do the following command: pip freeze
  2. Copy everything in the output and make a file called requirements and make sure it’s file extension is txt.
  3. Paste the output from pip freeze, then add this at the very top of the file “git+” (You do not need this line, if you are not going to host a discord bot. But follow all the other steps) without the quotes. Then save it.
  4. Next you must go into your CLI and use a command to make a new file called Procfile with no file extension. In windows powershell, the command is new-item Procfile
  5. Within Procfile enter the following:
    worker: python (name of The name of your file and extension will be inside the brackets. Remove the brackets of course.
  6. Enter the following commands in order: