While I am doing most my own websites are done in PHP, during the day I wrote web-based financial-planning applications for one of the largest deployment in Australia in this simple, elegant and yet powerful programming language — Python.
Python is a great language, and there are many great Python web frame-works out there (which is one of its strength but also weakness). However, we do not see heaps of ready-to-install open-source web applications written in Python, unlike PHP. One of the biggest issue is difficulties to deploy — PHP is pretty much everywhere, but many web hosts don’t even support Python.
Here I am going to share about getting your Python-based website/web-application hosted.
Diversity of Gateway Interfaces
One complexity involving developing and deploying Python-based web applications is its diversity of gateway interfaces with web servers. For example:
- CGI — more universally supported by the hosting companies. Slow because of folking Python interpreter processes.
- Fast-CGI — another old technology that are getting more supports from hosting companies, thanks to the popularity of Ruby on Rails. Used by frameworks such as web.py and Pylons.
- SCGI — a light-weight alternative to FastCGI, has a better Apache module, but rarely supported by hosting companies. Frameworks such as Quixote support it.
- Mod_Python — how’s running Python interpreter right inside Apache? Probably the most powerful way to deploy your app, but probably don’t expect having this privilege in a shared hosting environment. Preferred by Django and TurboGears.
- Proxy — making your web-app a long-running process, listening on a specific port for HTTP request, and get your main web server to proxy/forward that request. Preferred by Zope.
As there are probably a few dozen more Python frameworks out there, I think there might be other deployment options available. However we also neeed to note that some frameworks allows multiple gateway interfaces. Django for example, can be deployed as either FastCGI or mod_python. If your framework or application is written onto of WSGI, it should also support whatever interface that also has a WSGI implementation.
Note that I am not saying deployment should govern the Python web framework you use. No — use whatever framework that you feel comfortable with, whatever that fits your way of thinking. Just that your choice of framework might severe limit your hosting options (if you are also limited by budget).
Python Versions and Third-Party Modules
While Python 2.5 has just been released, many shared hosts still support only Python 2.3 (for example running a stable Debian or CentOS). Some frameworks have gone to the length to ensure they can run on older Python versions, but many require at least Python 2.4.
Also while Python claims to be “battery included”, you’ll find not all batteries required to develop a web application is provided by the host. Many of them can be easily downloaded and distributed along side with your own apps, but some of them require extension libraries to be compiled on the host. Lack of C compiler and related include files might make such task impossible.
You’ll also find many packages come in Python eggs and require setuptools to run. Expect a bit of trouble if setuptools is not available on your host.
So, which host is suitable to host my Python application?
You need “root”
The easiest option is to host on your own box, where you are root who can install whatever Python, 3rd party module and web server extension you want. Mod_Python? No problem. apt-get libapache2-mod-python or emerge mod_python, and few minutes later you are ready to deploy. Everything can be done with sudo — no more pleading emails to ask sysadmin of the hosting company to install certain package for you.
Getting a dedicated server or a virtual private server is probably the easiest way to have this privilege. Get a VPS over dedicated if you have lower budget — but you probably still need around $20/month to get a good performing VPS with sufficient memory and enough CPU slices.
Specialised Hosting
Being “root” is not for everyone, and managing a dedicated or virtual private server can be more stressful than prototyping a web application in Django. Sometimes you just want to let someone else handling all these system administration tasks, and you just want somewhere to drop you application in and make it online.
After a bit of googling, there is a surprisingly large number of hosting companies that are specialised in Python web-app hosting. What you should probably do is go to your framework’s home page, and check whether they have listed hosting companies that are friendly to that specific framework. Many of them provide mod_python in your own Apache process, or allow you to run a persistent process and set up proxy rule to forward the requests. For example:
- Django-friendly web hosts
- TurboGears hosting companies
- Zope Solution Providers (some of them are not hosting related)
Googe it also helps, at least you’ll get to see who is the most popular hosting company the is specialised in Python applications. I found WebFaction who has shared hosting plans from $14.50/month with 1 long-running process. Looks like they are pretty Python centric, and have very easy TurboGears deployment.
Shared Hosting
Running Python web applications on shared hosting spells trouble. However if you are on a very low budget, and have plenty of time to kill, then you might as well have hack up a work around and publish a HOWTO on running XYZ framework on some cheap shared hosting.
Personally I have experience with only two shared hosts.
-
DreamHost — there are plenty of howto’s on their wiki, explaining how to get Django and Trac to run on their shared hosting plans. Many suggest compiling your own Python.
That’s right. DreamHost provides access to C/C++ compilers, and allows you to compile your own Python executable. At least it is an option when the Python 2.3/2.4 installed on the server refuse to work. On my server Python 2.4 lacks many modules and C headers to compile extensions with, which renders it little use.
Despite having access to compilers, getting Python to run properly on DreamHost still requires a bit of patience and sometimes rubber chicken sacrifices. The CGI speed is also very slow as their server is usually overloaded.
-
Jumba — they are cPanel based and Python support is pathetic. Actually in their support forum they said explicitly that Python is not supported.
However Python 2.4 has been installed, but almost no 3rd party module is available — not even MySQLdb. All compilers are locked down so you can’t get your own C modules compiled.
At the end it is only useful to run sysadmin scripts and nothing else.
If you are thinking about signing up a shared hosting account for your Python applications, make sure you ask whether Python is actively supported. What versions are they running, what extension modules, and very importantly whether there’s a money back guarantee if you can’t get your app working in their environment.
Conclusion
Let me summarise. Python hosting is not as available as PHP, and you need to watch out for the gateway interface your framework uses, Python version and 3rd party module requirements.
While Python encourages “there is only one way”, there are many hosting options.
Best bet is dedicated or VPS. Find a specialised Python hosting company if you do not want to attend sysadmin part of managing a box. Finally, deploying of shared host is hard — make sure you ask a lot of questions before signing up to one.

Delicious
Digg
Reddit
Comments
Thank you for the article: “Python Web-Application Hosting.”
I would like to use frameworks like django or turbogears for python web-development, but it’s so frustrating to find decent hosting.
IMO: those frameworks were developed without regard to hosting realities. For example: turbogears requires python 2.4 - not 2.3 and not 2.5.
I can get PHP5 hosting for $10 a year (dollar-hosting.net).
In many respects Python is a better language than PHP. Python could be as popular, or even popular for web-development as PHP. But Python developers just don’t get it.
Post new comment