Deploying a Python App
In this simple tutorial, let's go through how we can deploy a Python application on Heroku with use of Heroku's Procfile
Set up Python App#
For this tutorial, I will use a sample python streamlit application - a mushroom classifier application
Streamlit is a popular python application for data science enthusiasts to host their datascience projects!
This git repository is already initialised and tracked, so we don't have to git init it
Create Procfile#
Define a worker process - to start the website
Create a Procfile at the root of the repository (already created in the git repo)
Over here, I ran sh setup.sh before running the streamlit application, for some configurations purpose.
You can add more worker processes if you want with
nameOfProcess: commands
Adding Heroku#
- Create Heroku application
To check if heroku is added to your git repository (you should see heroku)
To check the heroku apps you currently have
- Rename the created heroku application
When you first create the heroku app, a random name will be given, you will have to rename it yourself
OR if you already created a heroku application on the heroku website, you can link it directly
Test Heroku App#
Test the heroku application locally before we push it to heroku remote
This runs the web process (that was defined in Procfile) and checks it locally You can test and run multiple processes too
Open your localhost at specified port. This will be how it will behave on heroku web.
Deploying code#
- Push code to heroku
main or master branch
- Open Heroku website!
Open the heroku website at < app name >.heroku.com!