Problems with Python and shared hosting

The following problems are often encountered when trying to deploy a Python application in your web hosting account:

  • Python is not installed.
  • The installed Python interpreter is really old.
  • Common modules for web programming are not installed and your web host don't want to install them even if you ask nicely.
  • Persistent(long-running) processes are not allowed.
  • Your framework enables access to parts of the system you should not have access to in a shared envoronment.

So why is Python a problem?

The reasons for the incompatibilities between Python and shared hosting can best be understood by taking a quick look at the common frameworks for web programming with Python.

CGI

You can of course write CGI scripts using Python. Compared to other frameworks, CGI is primitive but it's available everywhere Python is installed. CGI scripts also suffer from the overhead of starting the Python interpreter every time a script is executed. Fine for websites with low traffic but a bottleneck for busier sites.

Mod_python

An Apache module for embedding the Python enterpreter within the Apache server, like mod_php which is the most common way of deploying PHP on a web server. Mod_python is more powerful in the way that it gives more access to Apache internals so you can do more advanced stuff. But this is a problem in a shared environment because it's possible to do things to Apache that will affect other websites using the same Apache instance.

CherryPy

CherryPy can serve as an example of a common model for Python web frameworks. A CherryPy application runs in its own server and you can deploy it as is or behind an Apache server. The problem with CherryPy and shared hosting is that since it runs its own server in a persistent process and that is normally not allowed in shared hosting environments because it locks down resources.

So it's not the language that causes the problems, it's the models that are used by the various frameworks. You might blame the Python masterminds for not including a powerful framework compatible with shared hosting with the standard distribution. But blaming someone does not solve anything.

Solving the problem

In general you have to look for a hosting provider that has a recent Python version, preferably 2.3, but 2.2 is also a good alternative. The second factor is the availability of 3rd party modules. F.ex. the MySQLdb should be installed in most cases. It's no good having Python and MySQL if you can't use them together. Other modules you might want access to are Cheetah, ElementTree and sqlite. Ask a potential hosting provider if they have the modules you would like to use, and if not, if they will install them for you.

Mod_python is not something the web host will install on request because of its power. One common mod_python hosting model is giving each customer his/hers own Apache process. This increases the use of server resources so prices will be a little higher. In other words, you don't get 1 gb disk space for $5/month in a mod_python enabled hosting account.

For other frameworks you also need permission to run persistent processes and probably a shell account for starting/stopping your server. Not that many to choose from but they exist.

A few hosting providers are more targeted at Python programmers than other. The perhaps most specialized Python host is WebFaction. They provide hosting for all common web frameworks, modules are installed on users request and multiple versions of Python are available.

A virtual private server is also an option. It demands a little more from the user, but if you already are a Python programmer that's probably not a large obstacle. As long as you have root access to your VPS you can do anything you want.