Guide
How to run a Python app on shared hosting
You can run a small Python app on shared hosting by creating a Python application in the control panel, choosing the version, setting the app root and WSGI entry point, and installing packages from a requirements file. It suits small Flask or Django sites and APIs. Heavy data processing or long-running jobs need a different kind of server.
The basics
How Python apps run on a web host
Python web apps usually follow a standard called WSGI. A framework such as Flask or Django produces an application object, and a web server passes requests to it through a small entry file. On shared hosting, a Python selector handles this: you give it your project folder and the entry file, and it connects the app to your domain.
You do not manage the server, so you do not install system software. Instead you work inside a virtual environment that the selector creates for your app, installing the packages your project needs from a requirements file.
This suits small web apps, internal tools, simple APIs and small Django sites. It is not a place for heavy machine learning, big data jobs or work that must run all day in the background. See our Python hosting page for what is included on each plan.
Setting up
Setting up a Python app, step by step
Prepare the project
Make sure the app runs locally, and that a requirements.txt file lists every package it needs.
Upload the project
Upload it to a folder in your hosting account over SSH or SFTP, outside the public web folder.
Create the application
In the control panel’s Python selector, create an application, choose the Python version, the app root and the address of the app.
Set the entry point
Tell the selector which file and object serves the app, such as the WSGI file and the callable inside it.
Install packages and start
Install the requirements, add environment variables for secrets and settings, then restart the app and test.
Worked example
A worked example: a small Flask quote tool
A builder wants a simple tool on his site where customers enter a few measurements and get a rough quote. A developer writes it in Flask, around a hundred lines, with a single page and a short calculation.
The developer uploads the project to a folder in the hosting account, creates a Python application with the selector, sets the app root and the WSGI entry file, and installs Flask from the requirements file. The tool is now served at a subdomain, quote.thebuilder.co.uk.
The page loads and the calculation works. The app uses little memory and is only used a few times a day, well within shared limits. For secrets, such as an email password used to send the quote, the developer uses environment variables in the selector. Updates mean uploading the changed file and restarting the app.
Django notes
If you use Django
Django needs a few extra steps. Set the allowed hosts to your domain, turn debug mode off in production and keep the secret key in an environment variable. Run the commands that collect static files into a folder the web server can serve, and set up the database connection, using one of the MariaDB databases included with your plan.
Run database migrations over SSH after deploying changes to your models, and keep a backup of the database before big changes. Check the Django documentation for the version you use, as settings differ between versions.
Remember that a Django project can be heavy. Check memory use after launch, and if the app is slow or restarts often, simplify it or consider whether it has outgrown shared hosting.
Troubleshooting
When the app will not start
The usual causes are small. The wrong Python version for the code, a missing package because the requirements were not installed, a wrong entry file or callable name, or a missing environment variable. Read the error log for the app, which normally names the file and line of the failure.
If you see a 500 error, check the log first. If you see a blank page or a timeout, the app may be crashing at start. Try running the entry file in the app’s virtual environment over SSH, where you can see the error message directly.
If you cannot find the cause, contact our live chat with the log lines. Our guide to fixing a 500 internal server error lists common causes on the server side.
Keeping it healthy
Logs, restarts and updates
After launch, watch the app for a few days. Check the error log and the memory use, and restart the app from the selector after each update. If it slows down or restarts on its own, read the log for the cause.
Keep packages up to date. Run a check for known vulnerabilities, update what you can and test before you redeploy. Pin the versions in your requirements file so the same code runs every time, and update them deliberately.
Keep your project in Git, and take a backup of the database before changes that alter it. A little routine keeps a small Python app running quietly for years.
Choosing a framework
Flask or Django for a small site
Flask is small and flexible, a good fit for a tool or an API with a handful of routes. Django includes an admin, user accounts, forms and a database layer, which saves time for a larger site but adds weight.
For a first project on shared hosting, start with the smaller choice that fits. You can always move to a heavier framework when the project needs it.
Host your project on UK servers
SSH, Node.js and Python selectors, free SSL and live chat open 24/7 on every plan, from 84p a month (£10.03 billed yearly).
FAQ
Common questions
Can I run Python on shared hosting?
Yes, for small apps, using a Python selector. Our plans include one.
Can I run Flask or Django?
Yes, for small sites and APIs. Check memory use, and avoid heavy workloads.
What is WSGI?
A standard that lets a web server talk to a Python web app through a small entry file.
How do I install packages?
Through the selector or over SSH, from a requirements.txt file in the app’s virtual environment.
Which database can I use?
MariaDB databases are included, and unlimited, on every plan.
Can I run background tasks?
Short scheduled jobs may work. Long-running or heavy workers are not suited to shared hosting.
Why does my app show a 500 error?
Read the app’s error log. Common causes are missing packages, wrong entry points and missing settings.
Keep reading
Related pages
Deploy your project on a plain yearly price
SSH, Node.js and Python selectors and free SSL on every plan, with a 15-day money-back guarantee.