advice needed for simple python web app

D

Dan Perl

I have a pretty simple python script and I would like to turn it into a web
application but web apps are a domain I know very little about. I know that
Twisted, CherryPy, Plone and Zope exist but not exactly what they do. I
need only advice on a direction to take. For instance a suggestion on which
application/framework to use would be great.

Basically, what I'm looking for is a web server that accepts an HTTP request
and invokes a python script. But I would like a "pythonic" solution so a
web server like Apache is a solution that I would like to avoid. The server
should also be as simple as possible to administrate.

I would be even interested in building a very simple web app server if there
is a framework that has all the basic components and there is good
documentation for how to use it.

Thanks,

Dan
 
M

M.E.Farmer

I am no web expert but have recently used cherrypy to 'webify' a
script. It is very easy to get going and has its own server or can be
run behind Apache.
The only real problem I see is that the docs are still a little lite
for the new 2.0 series ,but they do have a newsgroup where the author
still answers questions.
Cherrypy2 is fairly logical and most of it is covered in the examples
on there website.
I can not speak for the other packages,have not used them yet ;)
hth,
M.E.Farmer
 
P

Paul Rubin

Dan Perl said:
Basically, what I'm looking for is a web server that accepts an HTTP
request and invokes a python script. But I would like a "pythonic"
solution so a web server like Apache is a solution that I would like
to avoid. The server should also be as simple as possible to
administrate.

CGI and CGIHTTPServer (or whatever it's called) is conceptually the
 
D

Dan Perl

Paul Rubin said:
CGI and CGIHTTPServer (or whatever it's called) is conceptually the

The application is just something I'm playing with to learn a little bit on
web apps. It uses an HTML form to send an email. The form takes inputs
like the From:, To: and Subject: fields and a text field.

I found the "Internet Protocols and Support" chapter in the Library
Reference that covers also the CGIHTTPServer. It's definitely something I
will have to read. Thanks.

Dan
 
D

Dan Perl

M.E.Farmer said:
I am no web expert but have recently used cherrypy to 'webify' a
script. It is very easy to get going and has its own server or can be
run behind Apache.
The only real problem I see is that the docs are still a little lite
for the new 2.0 series ,but they do have a newsgroup where the author
still answers questions.
Cherrypy2 is fairly logical and most of it is covered in the examples
on there website.
I can not speak for the other packages,have not used them yet ;)
hth,
M.E.Farmer

Thanks. I am no web expert either so I appreciate advice coming from
someone who was in a similar situation.

Twisted and CherryPy seemed to me to be the main choices based on what I
understand from their front pages with my limited knowledge on web apps.
Twisted feels more "developed" but also more complex at the same time. I
wanted opinions before I invest the time in studying either one of them.
Your opinion helps.

Dan
 
M

Michele Simionato

Dan Perl:
The application is just something I'm playing with to learn a little bit on
web apps. It uses an HTML form to send an email. The form takes inputs
like the From:, To: and Subject: fields and a text field.

It is difficult to beat CGI + CGIHTTPServer for conceptual simplificity
and easy of use: however, Quixote comes close and it has a *much*
better support for forms. Here is an
example from the minidemo in the distribution, so you have an idea of
how the code looks
like:
from quixote.publish import Publisher
from quixote.directory import Directory
class RootDirectory(Directory):
_q_exports = ['', 'hello']
def _q_index(self):
return '''<html>
<body>Welcome to the Quixote demo. Here is a
<a href="hello">link</a>.
</body>
</html>
'''
def hello(self):
return '<html><body>Hello world!</body></html>'

def create_publisher():
return Publisher(RootDirectory(),
display_exceptions='plain')

if __name__ == '__main__':
from quixote.server.simple_server import run
print 'creating demo listening on http://localhost:8080/'
run(create_publisher, host='localhost', port=8080)

The exported methods of your directory class corresponds to Web pages;
_q_index
returns the main page, hello an hello word page. This works out of the
box with
no configuration at all, you don't need to create a cgi-bin directory,
nothing.
It is trivial to replace simple_server with a more serious server
(twisted_server,
scgi_server, etc. )

Notice: this example works in Quixote 2.0 which is currently in alpha.
Don't let
the "alpha" scares you: that means that the documentation is still a
bit rough and
few things are not fully settled down, but the framework is very much
usable.


Michele Simionato
 
P

Paul Rubin

Dan Perl said:
The application is just something I'm playing with to learn a little bit on
web apps. It uses an HTML form to send an email. The form takes inputs
like the From:, To: and Subject: fields and a text field.

Be careful of exposing that script to the internet. Spammers will
exploit it.
 
D

Dan Perl

Paul Rubin said:
Be careful of exposing that script to the internet. Spammers will
exploit it.

Do you mean publishing the script for other people to copy it or exposing
the web app so that other people may access it? Don't worry anyway, I won't
do either and I'm running 2 firewalls on my PC. It would be really naive to
expose the web app, wouldn't it?
 
B

Brian Beck

Dan said:
Basically, what I'm looking for is a web server that accepts an HTTP request
and invokes a python script. But I would like a "pythonic" solution so a
web server like Apache is a solution that I would like to avoid. The server
should also be as simple as possible to administrate.

As M.E.Farmer suggested, CherryPy is definitely what you are looking
for. I have done a bit of shopping around and this is pretty much as
straightforward as you can get.

From my experience, this appears to be the order from low-level to
high-level interfaces:

1. mod_python: As complex as you need it to be, since you can control
anything about the request & response process. But more up-front work
and decisions to make than CherryPy.
2. mod_python with Vampire: Directs you toward a specific publishing
framework that is similar to CherryPy.
3. CherryPy: Like Vampire but simpler and doesn't require mod_python.
The simplest blend between low-level server interface and
ease-of-publishing.
4. Twisted: Seems like this is a big package to work with, not sure how
easy it makes publishing once you get started-- better that someone else
comment on this.
5. Zope: The most complex solution, doesn't necessarily make the 'easy
things easy.' But covers all fronts in terms of what a user would ever need.
6. Zope with Plone: Adds a ton of publishing functionality. Has many
ways to extend, but none of them are fun. You'll have to learn such
complex APIs that Python will rarely help you.

Of course there are more, like Webware, but you didn't mention that and
I don't have experience with it.
 
D

Dan Perl

Michele Simionato said:
Dan Perl:

It is difficult to beat CGI + CGIHTTPServer for conceptual simplificity
and easy of use: however, Quixote comes close and it has a *much*
better support for forms.

So Quixote is another framework I will have to look into. Best of all,
though, after adding Quixote to the list I decided I have enough words to do
a search. There were a few interesting finds, but one single link that
points to the best of them is:
http://www.python.org/moin/WebProgrammingShootOut
 
P

Paul Rubin

Dan Perl said:
Do you mean publishing the script for other people to copy it or exposing
the web app so that other people may access it?

I mean installing the script on a server where spammers can run it and
stick you with the blame for people getting unwanted mail. There used
to be some similar perl scripts running all over the place until that
happened.
Don't worry anyway, I won't do either and I'm running 2 firewalls on
my PC. It would be really naive to expose the web app, wouldn't it?

Well, you should have some kind of user authentication if you expose
it, and you should read up a bit about security for web apps. Python
is actually not such a great language for this, but you certainly get
more readable code than you would with perl.
 
D

Dan Perl

Brian Beck said:
From my experience, this appears to be the order from low-level to
high-level interfaces:

1. mod_python: As complex as you need it to be, since you can control
anything about the request & response process. But more up-front work and
decisions to make than CherryPy.
2. mod_python with Vampire: Directs you toward a specific publishing
framework that is similar to CherryPy.
3. CherryPy: Like Vampire but simpler and doesn't require mod_python. The
simplest blend between low-level server interface and ease-of-publishing.
4. Twisted: Seems like this is a big package to work with, not sure how
easy it makes publishing once you get started-- better that someone else
comment on this.
5. Zope: The most complex solution, doesn't necessarily make the 'easy
things easy.' But covers all fronts in terms of what a user would ever
need.
6. Zope with Plone: Adds a ton of publishing functionality. Has many ways
to extend, but none of them are fun. You'll have to learn such complex
APIs that Python will rarely help you.

This is exactly the kind of summary that I think should be in a
WebProgrammingShootOut (see another one of my postings in this thread) but I
failed to find such a summary. Thanks, Brian! Anyone can add to the list?

BTW, there are other people who seem to have been also confused by the wide
spectrum of choices for this problem:
http://pyre.third-bit.com/hippoblog/archives/000058.html
 
P

Paul Rubin

Dan Perl said:
This is exactly the kind of summary that I think should be in a
WebProgrammingShootOut (see another one of my postings in this
thread) but I failed to find such a summary. Thanks, Brian! Anyone
can add to the list?

If you're just trying to get a conceptual understanding of web
programming, I suggest you start with cgi.

Next you might want to read Philip and Alex's Guide to Web Publishing:

http://philip.greenspun.com/panda/

It's out of date and the examples use Tcl and Oracle instead of
Python, but it's still a good explanation of how database-driven web
sites work. The rest (like languages frameworks) is just a matter of
picking some implementation parameters.
 
D

Dave Cook

I have a pretty simple python script and I would like to turn it into a web
application but web apps are a domain I know very little about. I know that
Twisted, CherryPy, Plone and Zope exist but not exactly what they do. I

I think CherryPy is the lightest and easiest if you need a built-in server.
I was impressed by its intuitiveness, though I don't really like the default
templating system.

I'm using Nevow (slick!) and Twisted now, but you pay for the flexiblility
with a steep learning curve, and lack of documentation and API stability are
an issue with Nevow.

Inspired by an example on Bruce Eckel's blog, I tried writing a web app with
only the server that comes with the standard lib, but it was just too hard
for me to build an app starting from that low a level. The frameworks help a
lot here.

Dave Cook
 
F

Fred Pacquier

Dan Perl said:
This is exactly the kind of summary that I think should be in a
WebProgrammingShootOut (see another one of my postings in this thread)
but I failed to find such a summary. Thanks, Brian! Anyone can add
to the list?

I myself am also into (very) simple web apps and hence simple, easy-to-
learn web frameworks.

CherryPy is a very nice kit, still simple enough but already (IMO)
somewhat on the powerful, batteries-included side for a beginner -- and,
as you noted, a bit under-documented at the moment.

There are a couple of others that will get you started without too much
effort (in part because simplicity is one of their design points) and
without limiting you too much either : Karrigell by Pierre Quentel and
Snakelets by Irmen de Jong.

They're somewhat similar in scope and concept : it will be mostly a
matter of which one 'fits your brain' best. Myself I settled on
Snakelets, not least because it has some of the better docs out there.
BTW, there are other people who seem to have been also confused by the
wide spectrum of choices for this problem:

That's an old debate in the Python world, yes. The "one true way to do
it" motto of the language itself doesn't apply to its web frameworks :)

See the recent "Ruby on Rails" threads for a discussion of whether this
is good or bad...
 
D

Dan Perl

Paul Rubin said:
If you're just trying to get a conceptual understanding of web
programming, I suggest you start with cgi.

Next you might want to read Philip and Alex's Guide to Web Publishing:

http://philip.greenspun.com/panda/

It's out of date and the examples use Tcl and Oracle instead of
Python, but it's still a good explanation of how database-driven web
sites work. The rest (like languages frameworks) is just a matter of
picking some implementation parameters.

This matches pretty much what I've decided to do. I'll start with cgi and
CGIHTTPServer because I'll learn more from that and then move to a
framework, quite likely CherryPy, although by that time I may change my
choice. Philip Greenspun's book looks good and I'll have to go through it.
Thanks for the advice.
 
P

Paul Rubin

Dan Perl said:
This matches pretty much what I've decided to do. I'll start with cgi and
CGIHTTPServer because I'll learn more from that and then move to a
framework, quite likely CherryPy, although by that time I may change my
choice. Philip Greenspun's book looks good and I'll have to go through it.
Thanks for the advice.

You might also look at the docs for HTML::Mason (www.masonhq.com) to
get a look at a reasonably mature template system, even if you don't
plan to use it (because it's in Perl and not Python). I'm not sure if
CherryPy is directly comparable. I haven't yet used any of the Python
template systems.
 
A

Ant

You might also look at the docs for HTML::Mason (www.masonhq.com) to
get a look at a reasonably mature template system, even if you don't
plan to use it (because it's in Perl and not Python). I'm not sure if
CherryPy is directly comparable. I haven't yet used any of the Python
template systems.

Mason is available for python

http://www.myghty.org/
 
R

Ray Cote

You might also look at the docs for HTML::Mason (www.masonhq.com) to
get a look at a reasonably mature template system, even if you don't
plan to use it (because it's in Perl and not Python).

There's a Python port of HTML::Mason called Myghty.
A fairly new project. I've just played around with it a bit
Well worth a look: <http://www.myghty.org/>

--

Raymond Cote
Appropriate Solutions, Inc.
PO Box 458 ~ Peterborough, NH 03458-0458
Phone: 603.924.6079 ~ Fax: 603.924.8668
rgacote(at)AppropriateSolutions.com
www.AppropriateSolutions.com
 

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

No members online now.

Forum statistics

Threads
474,219
Messages
2,571,117
Members
47,730
Latest member
scavoli

Latest Threads

Top