Python web development, really

Remi Delon remi at
Tue Jan 21 09:44:37 CET 2003

You might want to take a look at CherryPy (

> I would love to use Python instead of PHP for web development, but

> I have so far been confused by the options, or perhaps lack thereof,

> given my strict requirements. I would appreciate suggestions.


> I've looked at some Python options and have experience in quite a

> few platforms previously. I have always disliked PHP as a language,

> but at the same time have found it very accessible and useful.


> Possible solutions should do 99% of the following :


> * Run on the same hardware I use currently

It is 100% pure python so if python runs on your hardware, CherryPy will

> * Be as fast or faster than Apache+PHP

> (I'm sorry to say Zope/Roxen are not)

> (This might mean it must use Apache)


> * Use a similar amount of memory

> (ie. not Java/.NET related)

CherryPy uses a "compile source files and generate a single executable for
your website" approach, so it doesn't get much faster than that. And the
executable is very lightweight (only a few MB for a simple website)


> * Provide a fairly equivalent framework w/ sessions, cookies, get, post

> (Described in

> (eg. I should not have to write code to parse query strings, etc.)

> (PHP is somewhat unique in the ways it can bring in post variables)

CherryPy is also somewhat unique in the way it handles get and post
variables :-) Each page request is converted into a regular function call
and get and post variables become the arguments of the call:


is converted to:

index(var1="val1", var2=val2)

so you'll just have to write a function like this:

def index(var1, var2):

And it doesn't matter if var1 and var2 are sent via a get or a post or if
they're a short string or a large file that's being uploaded: they're
handled the same way.

Cookies are also automatically parsed and put in a nice python map for you.

Sessions are not implemented yet.

> * Allow all errors to be caught and handled so users never see them

> (I currently send them to an email address)

> (Users are notified an error occurred and a developer contacted)

That's how I set up my websites too :-) It's a trivial thing to do with
CherryPy. Chapter 14.3.4 of the tutorial shows how to do this.

> * Allow sending of raw binary data, for restricted file downloading

> (eg.

> (This requires header manipulation, specifically the mime type)

> (That sort of thing should be part of the framework 3 bullets up)

I'm not sure what you mean by that but CherryPy allows you to work on the
response header and body before it is sent back to the browser. So what you
want is probably quite easy to do with CherryPy.

> * Allow SSL secured credit card processing

> (I currently use PHP's libcurl+ssl module)

Yep, it supports SSL.

> * Allow similarly powerful regex capabilities

> (I currently use PHP's pcre module)

Well, you have access to all python modules from your code, so just pick the
one you want.

> * Big plus, but optional, auto prepend/append files

> (eg. Apache+PHP has .htaccess directives like this )

> ( php_value auto_prepend_file "_header.php" )

> ( php_value auto_append_file "_footer.php" )

> (granular down to the directory

You can do that with CherryPy AOP feature. Check out this HowTo:

> * Finally, very optional plus, global application scoped variables

> (PHP does NOT allow this, but I know why)

> (I do not want to hear why you think this is bad)

> (I know why it is good, I know why it can be bad)

Yep, you can use global variables.

> Some of these things likely already exist in Python itself and thus

> in anything which uses Python in a web development solution, but I am

> mentioning them explicitly because they are indeed still requirements.

> Plus explicit is better than implicit, as I'm sure everyone knows. ;-)


> Some links for future and others' reference :




> (dead? that's too bad)






> I hope I have not forgotten anything which will lead this thread to hell.

Well, you've forgotten CherryPy :-)

I suggest you take a look at, check out the small
online demo and take a quick look at the documentation (HowTo and tutorial).

If it doesn't meet your requirements, please tell me what is missing/you
don't like so I can improve it :-)



More information about the Python-list mailing list