How to Deploy a Python App to Production with Git

5th June 2023

You can use GitPushLive to deploy python apps to your own servers. This allows you to choose from a large number of server providers and configurations to best meet your cost / performance requirements. It also has no lock-in and allows you to add additional databases and services as required without additional cost.

Deploying a Python App to your GitPushLive Server

1. Pull in our python sample app with the following commands

# clone our demo repository 
git clone [email protected]:GitPushLive/python-sample.git 
# change into the project folder 
cd python-sample 
# configure environment
python3 -m venv .venv
source .venv/bin/activate
# install dependencies
pip3 install -r requirements.txt
# test the app 
python3 -m flask run

If you open your web browser at should see the simple output of “Hello World!”

You can now press ctrl + c to stop the python app from running.

2. Deploy this app to your server ( below presumes your server is called )

# add your git remote 
git remote add live [email protected]:python-sample 
# push it live 
git push live

If you open your web browser at you should now see the app running on your live server

Sample Project Explained.

The above code is able to run because

  • Dokku sets up an Nginx reverse proxy to manage your traffic from the above custom domain.

  • The Python environment is setup with the Dockerfile here.  

  • Dokku runs the command held in the Procfile here.

  • The app knows which port to listen on by using the PORT environmental variable

The above app is a very basic flask app with a single endpoint. However the principle should be the same for more complex applications. We plan to add more tutorials on how to use databases from with your Python apps.

Other Deployment Options

Manual Deployment

Deploying Python apps can be tricky as you need to setup some kind of server, process manager, reverse proxy etc. To do this without GitPushLive you can follow something like the Digital Ocean Tutorial Here.

Using a Proprietary PAAS Solution

Another way is to sign up to one of the many App platforms to host it for you, you’ll be tied to their eco system so have to pay extra for add-ons like database, backups etc. However this may be a good option if your app fits within their free tier or vendor lock-in ins’t a concern.