Let’s make Python web friendly
Here is a great language, so powerful and fun to write code with yet it’s not really being used for developing web applications.
There is no easy way to run your Python scripts like PHP, you will either have to run them as CGI and there is a lot of pain associated with that if you know what I mean, sometimes you only get “Internal Server Error” and you have to pull your hair out until you find out what the problem is.
The other thing you can do is to use something like mod_python, which is almost impossible for an average user to install and it imposes some restrictions on you. For example, you have to have certain methods with certain names and mod_python will call those for you.
I’m in the process of starting to make a module for Apache (and the Lighty and then IIS hopefully) that has three great qualities that will help getting Python out there for web developers to try:
1 - It will install very, very, very easily on all platforms, it will be ready to go, no pain. The server admin just runs install and it’s there, ready to use.
2 - It doesn’t do anything fancy, nothing fancy, it only hands over the Python script to the Python interpreter and writes the output to Apache, that’s it.
3 - You can put your Python scripts anywhere you want just like PHP.
The goals of this project:
1 - To make Python readily available for anyone to try, without a lot of pain, as easy as PHP.
2 - To have this new Python module installed on all the hosting packages.
3 - To have this new Python module be part of all Linux distributions.
4 - To have a lot of web developers finally using it and enjoying it.
5 - To start the development of a lot of open source web apps written in Python.
If you want to help me with this, leave a comment, you don’t have to be a C wizard.
Otherwise, please help me spread the word in any way you want.
Thanks!


Graham Dumpleton said,
November 17, 2008 @ 6:40 am
Writing an Apache module which supports using Python isn’t trivial. Do you really know what you are getting in to?
Also, have you even looked around at what is out there? Do you know what WSGI is and consequently what the mod_wsgi module for Apache does?
Codehead said,
November 17, 2008 @ 6:54 am
Yes I know it’s not trivial and I know what I’m getting into.
I don’t like any of the Apache modules, they are one of the reasons why Python is not very popular among web developers.
Graham Dumpleton said,
November 17, 2008 @ 7:41 am
Hmmm, you didn’t say whether you are aware of what WSGI is? WSGI is where things are going with Python web applications. If what you are doing isn’t compatible with that, unlikely you will get any mind share as it would mean people tying themselves to your specific way of doing things as well as it not being portable to other hosting mechanisms. If you do implement to WSGI interface, then you would be going up against existing mod_wsgi, which begs the question of why you aren’t saying what the issue with mod_wsgi is and perhaps suggesting how it could be improved to meet what you perceive as goals.
Carl J. Nobile said,
November 17, 2008 @ 10:56 am
What could be easier than WSGI? Especially when using mod_wsgi. The Apache configuration is very simple nothing like mod_python which, as you say, is quite difficult. Almost all the major Python frameworks can use it including Django, Pylons, CherryPy, Turbogears, Zope, and others. WSGI is the Python standard Web Service Gateway Interface and is part of the python install already and blessed by Guido himself.
I wish you luck if you can come up with something better and can get Guido to put it in a standard Python install. If you go with WSGI, the standard, then mod_wsgi has already done the Apache interface and quite well also. WSGI is the way to go at this point in time.
By-the-way Graham is the creator of mod_wsgi and worked on mod_python which he himself doesn’t like much anymore. Graham correct me if I’m wrong.
Kevin Orgiven said,
November 17, 2008 @ 11:09 am
Mr. Dumpleton,
Don’t trying to come on here and scare someone out of attempting to explore a realm you may consider yourself an ‘expert’ in. Yes, you’ve done a lot to contribute to support python web development, however what I’m trying to say is individuals with your exact demeanor towards competition is what impedes on any sort of growth amongst an area or industry. Reality check, mod_wsgi isn’t the final solution.
Codehead said,
November 17, 2008 @ 3:14 pm
Graham,
I’m aware of WSGI, http://www.python.org/dev/peps/pep-0333/ and I see your point here but I think Python has to learn from PHP a little.
I want to be able to name a script *.py, put it anywhere on my web server and point my browser to it. I hate regulations, I think these modules should let you just print things to the web server and if you want a framework, then use one on top of that.
Carl,
I’m not trying to compete with anyone, I’m just frustrated with the options. I’m also a supporter of open-source and admire Graham for what he did and all his contributions.
Kevin,
I will hopefully start this project next week, like I said, I don’t have a lot of time but I’m very motivated.
Gert Cuykens said,
November 17, 2008 @ 7:36 pm
Configuration off mod_wsgi to be as php putting your .py files anywhere you want. I am not against the idea of making something new , i am against the not working together part to achieve the same goal !!! What Graham is trying to say is “I am working my ass of on this peace of code, and I would appreciate it if we python people where walking in the same direction” I suggest to just do some warming up on some issues on mod_wsgi that are still open and when you solve a thing or two start making suggestions on doing different things. I mean currently mod_wsgi plain hello world benchmarks are almost as fast as static files. Come on !!! What the hell are you going to do different at the core of something this fast ? You may or may not like the wsgi interface of it but at least take a good look at the code. Crazy ideas being tossed around to make it run language independent and stuff. Mod_wsgi is being made by a decade of experience on the filed, learning from the mistakes of mod_python. Are you really going to trow this all away ?
User www-data
Group www-data
Listen 80
Listen 443
ServerRoot “/usr/lib/apache2″
ErrorLog “/var/log/apache2/error.log”
LogLevel info
LoadModule ssl_module modules/mod_ssl.so
SSLCertificateFile /etc/apache2/ca.pem
SSLCertificateKeyFile /etc/apache2/key.pem
SSLSessionCache dbm:/var/log/apache2/ssl_cache
SSLSessionCacheTimeout 600
SSLEngine Off
LoadModule wsgi_module modules/mod_wsgi.so
WSGIProcessGroup %{GLOBAL}
WSGIApplicationGroup %{GLOBAL}
WSGIPythonPath /srv/www/lib
LoadModule mime_module modules/mod_mime.so
TypesConfig /etc/mime.types
DefaultType text/plain
AddHandler wsgi-script .py
AddType text/xml .py
LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
ServerAdmin gert.cuykens@gmail.com
ServerName 127.0.0.1:80
DocumentRoot “/srv/www”
Options ExecCGI Indexes FollowSymLinks
DirectoryIndex index.htm
IndexIgnore .htaccess .??* *.pyc
Order Deny,Allow
Allow from all
Codehead said,
November 17, 2008 @ 7:50 pm
Gert,
Putting .py files anywhere is just one of the issues. Graham didn’t throw mod_python away by writing mod_wsgi…
I want to work together with everyone who’s interested in what I want to create. I have this idea and I will try my best to make it happen and I believe it will be good for Python.
Graham Dumpleton said,
November 17, 2008 @ 7:52 pm
Kevin, I am not trying to scare anyone off. I am more interested in just understanding peoples motivations and what they think is wrong with what is out there. From understanding more about what people see as the problems then I can in turn learn how the things I work on could be changed to make things easier or support other ways of working.
If you knew my history and how I get involved in things you would know that I help all manner of people out even where it is a project that I am not directly involved in. This has included me helping people with writing their own custom modules for hosting Python under Apache or other web servers. So, I am not saying mod_wsgi is the only way and you will find that I still often suggest people use mod_python, fastcgi/scgi or proxy solutions instead. It really all depends on what people want to do as to whether something is appropriate.
Codehead, by the sounds of it you may want to have a look at http://www.freenet.org.nz/python/pyweb/docs/pyhp.html as it looks to overlap with what you have in mind. They also are trying to develop a module for Apache which directly supports their system. This is actually how I came across it as they recently approached me in respect of the custom Apache module they are writing to handle Python and their templating system and some issues they are seeing in interfacing with Apache.
I still have to properly look through what these people are doing, but the general concept of having an application handle a custom template file which is the target of a HTTP request is also able to be managed using mod_wsgi. It is just a matter of configuring Apache appropriately with a combination of Action and AddHandler directives. Even if not a template file which needs special processing, mod_wsgi already allows you to stick WSGI application script files anywhere you want in document directories just like PHP does.
Finally, be aware that using ‘print’ to produce response opens up a huge can of worms. This is because it implicitly directs output via stdout. To have it do otherwise would require byte code manipulation due to it being a keyword. Replacing stdout itself to try and redirect it as some do is not a good solution as it has issues with multithreading, plus that some third party Python modules think they can blindly dump debug output to stdout and/or do other strange things with it, all of which can screw up a response.
Graham Dumpleton said,
November 17, 2008 @ 8:07 pm
Gert, that isn’t what I am saying. I am not expecting people to jump on the mod_wsgi band wagon. I am more than happy to see people explore their own solutions, more so if they want to try and do a custom Apache module of their own as can possibly learn from different approaches people may have. I also may be able to contribute something to these other people based on what I have learnt as to what is and what isn’t possible, or where general difficulties may lie. I may also be aware of other packages that they may not be aware of which may be relevant and therefore partly do what they want and therefore save them some trouble.
So, perhaps let me speak for myself next time.
Codehead said,
November 17, 2008 @ 8:19 pm
Graham, pyhp is not what I’m looking for either, but I would really like to talk to you about this directly, please let me know if you have the time and if you are interested.
Graham Dumpleton said,
November 17, 2008 @ 8:41 pm
Codehead, that is if I can contact you. Your blog seems to not be taking my comments any more and can’t for starters correct that URL should have been http://www.pyhp.org/. There seem to be multiple projects with same name, although maybe one is old site. Since can’t find your email either, you perhaps may want to mail me.
Codehead said,
November 17, 2008 @ 9:11 pm
Thanks Graham, I will email you.
Gert Cuykens said,
November 17, 2008 @ 10:01 pm
Damit Graham now you made me look like the bad guy again. I suppose to be the good, smart, wise and hansom one