Python for Webscripting (like PHP)

F

Florian Lindner

Hello,
I've been using Python a lot for scripting (mainly scripts for server
administration / DB access). All these scripts were shell based.

Now I'm considering using Python (with mod_python on Apache 2) for a web
project, just how I've used PHP in some smaller Projects before (<?php
print "foo" ?>)..

How suitable is Python for these kind of projects? What do think? Does the
stdlib offers all basic functions for this kind of requirements?

Thanks,

Florian
 
M

Micetto Nero

Florian Lindner ha scritto:
Hello,
I've been using Python a lot for scripting (mainly scripts for server
administration / DB access). All these scripts were shell based.

Now I'm considering using Python (with mod_python on Apache 2) for a web
project, just how I've used PHP in some smaller Projects before (<?php
print "foo" ?>)..

How suitable is Python for these kind of projects? What do think? Does the
stdlib offers all basic functions for this kind of requirements?

You can use the Python Server Pages, that are analogous to ASP, PHP and JSP.
<http://www.webwareforpython.org/>
<http://www.webwareforpython.org/Webware/PSP/Docs/index.html>
 
A

Alessandro Bottoni

Florian said:
How suitable is Python for these kind of projects? What do think? Does the
stdlib offers all basic functions for this kind of requirements?

Python is extremely well suited for the web-app development and the STDLib
supply most of what you need for this task. As a matter of fact, the easy
development of web applications was one of the main focuses of the Python
community since Rel 1.0. Thanks to the hard work of its supporters, Python
is now widely considered one of the best tool you can use for developing
web applications, even better than PHP.

Have a look at these chapters of the official Python documentation to get
convinced of what I'm saying:
Chap. 11: Internet Protocols and Support
Chap. 12: Internet Data Handling
Chap. 13: Structured Mark-Up Languages Processing

(Python has even been told to be used by Yahoo! and Google, among others,
but nobody was able to demonstrate this, so far)

Despite this, keep in mind that developing a _real_world_ web application
without the right tools (session management and templating, in particular)
is quite hard, no matter which language you use (even with PHP).

Have a look at the many web frameworks mentioned at http://www.python.org/
and at http://www.vex.net/parnassus/ and choose the one you feel best
suited for your task.

Among these web framework, a couple of them deserve a particular attention:

Maki is a XML based framework, very similar to the java-based Cocoon:
http://maki.sourceforge.net/
http://cocoon.apache.org/

Albatross is aimed to stateful applications:
http://www.object-craft.com.au/projects/albatross/

Regarding the template engine, the best one I'm aware of is Cheetah:
http://www.cheetahtemplate.org/

A last word: beware of PSP (Python Server Pages). If used in the wrong way,
this tool (like the original Java Server Pages) can make a real mess of
your code (because of the inextricable tangle of Python and HTML code you
can create).

CU
 
L

Luis M. Gonzalez

Mod_python has a PSP (python server pages - ala php) implementation.
However it's still not mature enough and, imho, it has a serious
drawback in its way to handle indentation. But this is just the first
release and I hope it will improve in the near future.

My favorite is Karrigell ( http://karrigell.sourceforge.net ).
It is a pleasure to work with, minimalistic, simple and to the point.
No template language needed, just regular python and html and, as far
as I know, mod_python integration is uderway.

Hope it helps...
Luis
 
V

Valentino Volonghi aka Dialtone

Alessandro Bottoni said:
(Python has even been told to be used by Yahoo! and Google, among others,
but nobody was able to demonstrate this, so far)

?

Google and Microsoft and Nokia had talks during PyCon 2005.
If you look at the GMAIL help system you would see that all the links in
there end in .py.
Blogger is almost completely built with python.
Google is also one of the members of the PSF.

What should be demonstrated?
 
S

Steve Holden

Peter said:
Nobody, except Google's founders?

http://www-db.stanford.edu/~backrub/google.html

(Among many other references.)

-Peter

Plus, may I remind the world, PyCon DC 2005 had a keynote by far-from
obscure Python supporter Greg Stein, an engineering manager at Google,
giving a talk entitled "Python at Google".

There's informal evidence that the Python secret is getting out. Sharpen
up your resumes, guys, you may not have to limit Python to home usage
soon :)

regards
Steve
 
S

Scott Kilpatrick

Alessandro said:
(Python has even been told to be used by Yahoo! and Google, among others,
but nobody was able to demonstrate this, so far)

If you use Yahoo! Maps, you will notice they use Python.

Scott
 
A

Aahz

There's informal evidence that the Python secret is getting out. Sharpen
up your resumes, guys, you may not have to limit Python to home usage
soon :)

OTOH, the big sucking sound from Google and Yahoo (plus other places
like Ironport) is making it more difficult to hire Python programmers in
the Bay Area...
 
T

Terry Reedy

Peter Hansen said:

I think the relevant paragraph is worth quoting here (****s added):
"
In order to scale to hundreds of millions of web pages, Google has a fast
distributed crawling system. A single URLserver serves lists of URLs to a
number of crawlers (we typically ran about 3). Both the URLserver and the
crawlers are implemented in **Python**. Each crawler keeps roughly 300
connections open at once. This is necessary to retrieve web pages at a fast
enough pace. At peak speeds, the system can crawl over 100 web pages per
second using four crawlers. This amounts to roughly 600K per second of
data. A major performance stress is DNS lookup. Each crawler maintains a
its own DNS cache so it does not need to do a DNS lookup before crawling
each document. Each of the hundreds of connections can be in a number of
different states: looking up DNS, connecting to host, sending request, and
receiving response. These factors make the crawler a complex component of
the system. It uses asynchronous IO to manage events, and a number of
queues to move page fetches from state to state.
"
This seems to have been about 2000. Of course, bottleneck code may have
been rewritten in C, but Google continues to hire Python programmers (among
others).

Terry J. Reedy
 
P

Peter Decker

OTOH, the big sucking sound from Google and Yahoo (plus other places
like Ironport) is making it more difficult to hire Python programmers in
the Bay Area...

Then start looking for telecommuting people. There are lots of us who
can use work and have excellent telecommuting references, but who
don't happen to live in a major metro area!
 
E

Erik Max Francis

Peter said:
Then start looking for telecommuting people. There are lots of us who
can use work and have excellent telecommuting references, but who
don't happen to live in a major metro area!

And then there's some in the Bay Area who wouldn't mind telecommuting,
either ... :)
 
S

Steve Holden

Aahz said:
OTOH, the big sucking sound from Google and Yahoo (plus other places
like Ironport) is making it more difficult to hire Python programmers in
the Bay Area...

Not to mention the large Python gravity field a few hundred miles South
emanating from Industrial Light and Magic.

But don;t expect "Google and Yahoo suck" to be a popular compaint ;-)

regards
Steve
 
J

Jon Hewer

I like the look of cheeryPy - snyone know if its easy to get it
running on top of Apache?

Thanks
 
F

Florian Lindner

Florian said:
Hello,
I've been using Python a lot for scripting (mainly scripts for server
administration / DB access). All these scripts were shell based.

Now I'm considering using Python (with mod_python on Apache 2) for a web
project, just how I've used PHP in some smaller Projects before (<?php
print "foo" ?>)..

How suitable is Python for these kind of projects? What do think? Does the
stdlib offers all basic functions for this kind of requirements?

An email I got from Dan Richter. Since he has problems with his news/mail
gateway I forward it with his permission for the benefit of others.

Florian

- - -

Python is great for "heavy lifting": when most of the work is done
behind the scenes and outputting the HTML is relatively trivial. An
example would be a program that searches archives or computes
derivatives.

But PHP is designed for web pages and is quite powerful. If you can
reasonably do a job in PHP, you probably should. Web sites written in
Python usually involve lots of statements like these:
uri = os.environ['HTTP_URI']
print '<html><head><title>' + theTitle + '</title></head>'
print '''<body><div>
<h1>The answer to your question</h1>
<p>After lots of computing, here's what
we discovered.</p>'''
And so on. As you can see, PHP allows you to embed HTML much more
gracefully, as well do other web-like things such as retrieve URL query
string parameters more easily. So PHP is preferable for most web sites.

Depending on what you want to do, you might also consider Perl and Java
Servlets.

- - -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top