By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

Web server with Python

P: n/a
Hi all,
after my unsuccessful try to run Apache 2 with mod_python and Python
2.3, I am looking for an alternative approach.
My aim is to write a small web-based application:

Python
- the solution must be based / usable on Python 2.3

Portability
Targeted plaforms are
- Windows 2000 Server
- Windows XP Pro
- AIX 5.1

Webserver:
- supporting up to 50 concurrent client connections
- must be able to use Python 2.3 to create dynamic pages
I can think of 3 alternatives to Apache:
- Medusa
- Twisted
- Zope
Which one is the easiest to work with? Which one is known to work on an
AIX 5.1 platform, for instance?

Persistent storage
- Is ZODB easily usable from outside Python, i.e. to produce reports
without reverting to programming?
- Is MySQL with Python a good combination?
Regards,
-PU
Jul 18 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a

"Patrick Useldinger" <p.**********@myrealbox.com> wrote in message
news:tn********************************@4ax.com...
Hi all,
after my unsuccessful try to run Apache 2 with mod_python and Python
2.3, I am looking for an alternative approach.
My aim is to write a small web-based application:

Python
- the solution must be based / usable on Python 2.3

Portability
Targeted plaforms are
- Windows 2000 Server
- Windows XP Pro
- AIX 5.1

Webserver:
- supporting up to 50 concurrent client connections
- must be able to use Python 2.3 to create dynamic pages
I can think of 3 alternatives to Apache:
- Medusa
- Twisted
- Zope
Which one is the easiest to work with? Which one is known to work on an
AIX 5.1 platform, for instance?
I've worked with Zope, Medusa and Twisted. If you can use anything found on
www.zope.org under resource and like to do everything in a webpage, not
doing much programming yourself, then Zope might be the thing. It covers the
python-code a bit much for my taste ( a bit being a huge understatement ).

Medusa is easy to work with but I had some problems with blocking and
form-handling ( mainly posted files etc. ) but it might have been my lack of
understanding back then.

Twisted is very easy to get a grip on if you stay away from Woven and use
the resource-class yourself. I can produce a very simple example if you
like. I find Twisted to have a very steep learning curve in some areas and
the project do have a feeling being "under construction", but the
developers/mailing-list are very friendly and helpful and glad for input.

I haven't done anything on AIX so I don't know anything about portability.
I'd go for Twisted if you want control, Zope if you can use any existing
"product" available at zope.

Persistent storage
- Is ZODB easily usable from outside Python, i.e. to produce reports
without reverting to programming?
- Is MySQL with Python a good combination?


MySQL is easy to work with using Python, so yes. My experience with ZODB has
not been good. I had problems compiling earlier version of it ( probably my
fault but still ) and I quickly found out that I needed SQL to be able to
store and retrieve data the way I wanted. If MySQL is too much for you take
a look at SQLite, it has a python-module and easy to install/distribute and
it is a "real" sql-database, ie. it can understand SQL and feels like a
SQL-database.

Thomas W
Jul 18 '05 #2

P: n/a
Thomas Weholt wrote:
- must be able to use Python 2.3 to create dynamic pages
If you can use anything found on www.zope.org under resource and
like to do everything in a webpage, not doing much programming
yourself, then Zope might be the thing.


However, Zope still doesn't run on Python 2.3, does it?
// Klaus

--<> unselfish actions pay back better

Jul 18 '05 #3

P: n/a
Thomas Weholt wrote:

[snip]

Twisted is very easy to get a grip on if you stay away from Woven
and use the resource-class yourself. I can produce a very simple
example if you like. I find Twisted to have a very steep learning
curve in some areas and the project do have a feeling being "under
construction", but the developers/mailing-list are very friendly
and helpful and glad for input.
The Twisted mailing list has been down for a few days. They're
moving.

To get Twisted, check:

http://www.twistedmatrix.com/

I agree with the positive comments about Twisted.

The Twisted documentation seems pretty good and fairly extensive.
And, for Web applications, here is a document I've written that
might help you to get started:

http://www.rexx.com/~dkuhlman/twisted_patterns.html

I've checked this document carefully myself, but have not yet been
able to get any Twisted experts to review it yet (again, the email
list is down temporarily), so "reader beware".

Twisted is more than Web apps, by the way.

[snip]
MySQL is easy to work with using Python, so yes. My experience
with ZODB has not been good. I had problems compiling earlier
version of it ( probably my fault but still ) and I quickly found
out that I needed SQL to be able to store and retrieve data the
way I wanted. If MySQL is too much for you take a look at SQLite,
it has a python-module and easy to install/distribute and it is a
"real" sql-database, ie. it can understand SQL and feels like a
SQL-database.


PostgreSQL also seems to work well with Twisted. See my document
(mentioned above) for code examples on using PostgreSQL (or other
relational databases, with minor changes) with Twisted.

Dave

--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dk******@rexx.com
Jul 18 '05 #4

P: n/a
Quoting Patrick Useldinger (p.**********@myrealbox.com):
Webserver:
- Medusa
- Twisted
- Zope
Which one is the easiest to work with? Which one is known to work on an
AIX 5.1 platform, for instance?
Medusa is pretty low-level. It's really just a server framework with
not much in the way of form handling or other niceties.

Zope is pretty high-level. It's at its best in doing content
management, and does a decent job of being an appserver. Its biggest
shortcomings, in my disreputable opinion, are its use of an object
database and its innovative features.

The object database makes it hard to edit stuff except in the web
interface. Several of the innovative features -- security roles, user
authorization, and acquisition to name a few -- make serious,
highly-dynamic development under Zope challenging. You are effectively
learning the intricacies of a highly-evolved application. On the other
hand, if your applications fit into typical categories -- content
management, information publishing, forums, etc -- Zope has lots of
pre-built tools that you can use.

Also, it really depends on how dynamic your "dynamic" is. A friend of
mine runs a job database: not too many writes to the DB and lots of
reads from it, a couple common data types. Zope would be okay for his
stuff. I work on a site where every user submits a profile, and lots
of information is exchanged between users, and every page's content is
entirely different based on the current user's nest of objects. We had
to punch a hole in the side of Zope and we suffer from performance
problems due to the highly dynamic content.

I've looked at Twisted but not used it. It's got some of the low-level
features that Medusa does, but it's also got some of the higher-level
form handling and such that you get out of Zope. It's worth a look.

Also worth a look is WebWare. I've only done a little bit with
WebWare, but it's very similar in architecture and execution to the
Java Servlet API. If I were starting from scratch, that would be my
toolkit of choice for a highly stateful, highly dynamic app.

I can't speak to AIX. You might be the first to try some of these on
those platforms. My advice in those cases is to look at the stuff that
uses as little C code as possible, because gauging portability isn't
too easy.
Persistent storage
- Is ZODB easily usable from outside Python, i.e. to produce reports
without reverting to programming?
No. ZODB is an object database. You put objects in and build your own
indexes to those objects. You get them out the same way you put them
in. ZODB is easily usable from /inside/ Python though: it does not
require you to explicitly handle the object-to-relational mapping that
a SQL database will.
- Is MySQL with Python a good combination?


I can't comment on MySQL directly, because I've used it only a little
from Python. SQL in general suffers from the difficulty that you need
to write the queries to store and retrieve your objects from the
databse yourself: that process is called object-to-relational mapping,
and it's hard to do well and easy to do in ways you'll regret later.
But, the SQL databases are easily accessible from a quadrillion other
tools that can do reporting for you.

Hope this helps,
--G.

--
Geoff Gerrietts "I think doorways are sexist."
<geoff at gerrietts net> --Jayson Lockwood

Jul 18 '05 #5

P: n/a
Quoting Klaus Alexander Seistrup (sp**@magnetic-ink.dk):
Thomas Weholt wrote:
- must be able to use Python 2.3 to create dynamic pages


If you can use anything found on www.zope.org under resource and
like to do everything in a webpage, not doing much programming
yourself, then Zope might be the thing.


However, Zope still doesn't run on Python 2.3, does it?


Also true! Beta versions recommend/require 2.2.3, and current
production last time I checked (last week? week before?) requires
2.1.3 instead.

--G.

--
Geoff Gerrietts "Overspecialize and you breed in weakness.
<geoff at gerrietts net> It's slow death." -- Maj. Motoko Kusanagi
http://www.gerrietts.net (Ghost in the Shell)

Jul 18 '05 #6

P: n/a
On Thu, Sep 11, 2003 at 05:19:50PM -0700, Dave Kuhlman wrote:

The Twisted documentation seems pretty good and fairly extensive.
And, for Web applications, here is a document I've written that
might help you to get started:

http://www.rexx.com/~dkuhlman/twisted_patterns.html

I've checked this document carefully myself, but have not yet been
able to get any Twisted experts to review it yet (again, the email
list is down temporarily), so "reader beware".


Here's some quick feedback for you in the meantime, then :)

] Here is an example of a class that dispatches requests:
]
] class ResourceDispatcher(resource.Resource):
]
] isLeaf = True
]
] def render(self, request):
] done = False
] if len(request.postpath) == 1 and request.postpath[0]:
] if request.postpath[0] == 'show_plants':
] dbaccess = dbmod.DBAccess(registry)
] dbaccess.show_plants(request)
] done = True
] elif request.postpath[0] == 'show_plants_by_rating':
] dbaccess = dbmod.DBAccess(registry)
] dbaccess.show_plants_by_rating(request)
] done = True
[...etc...]

Ugh. You can do this with much less pain:

class ResourceDispatcher(resource.Resource):
isLeaf = True
def render(self, request):
if len(request.postpath) == 1 and request.postpath[0]:
name = request.postpath[0]
dbaccess = dbmod.DBAccess(registry)
try:
method = getattr(dbaccess, 'webrequest_' + name)
except AttributeError:
pass
else:
method(request)
return NOT_DONE_YET
content = Content_Dispatch % (
request.postpath,
request.args,
time.ctime(),
)
request.write(content)
request.finish()

Note that the getattr-with-a-prefix idiom is used in several places in
Twisted, e.g. twisted.web.xmlrpc and twisted.spread.pb, among others.

] def delete_plant_step_3(self, resultlist):
] self.db.getPlants().addCallbacks(self.gotPlants,
] self.db.operationError,
] callbackArgs=())

callbackArgs defaults to (), there's no need to explicitly pass it.

] def add_plant_machine(self, *args):
] if self.state == STEP_1:
] self.db = PlantDatabase(self.dbpool)

Again, prefixed methods make this much nicer:

class Foo:
state = 'step1'
def add_plant_machine(self, *args):
method = getattr(self, 'state_' + self.state, self.invalidState)(*args)

def state_step1(self, *args):
self.db = PlantDatabase(self.dbpool)
# ...etc...
self.state = 'step2'

def state_step2(self, *args):
# And so on...

This is much nicer way to construct a state machine than a massive
if/elif/elif/elif/... block. A good example of this in Twisted is
twisted.protocols.smtp (and there's a helper class at
twisted.protocols.basic.StatefulStringProtocol -- but that's not really
relevant to web programming)

Even nicer would be thinking of meaningful names for the states instead of
just "step1", etc :)

] class PlantDatabase(adbapi.Augmentation):

Augmentation is deprecated, and will die soon. You're better off just using
adbapi.ConnectionPool directly.

] class GlimpseTextRepository:
] """Update and retrieve from the Plant_DB database.
] """
] def __init__(self):
] pass

Why not just omit the redundant __init__ definition entirely?

] # ..snip..
] self.deferred.addCallback(self.got_query_results)
] # ..snip..
]
] def got_query_results(self, results):
] return results

Your comment below the code is right; you can just omit this entirely. That
callback is redundant.

] os.system(cmd)

This is a no-no in Twisted -- it will block. Use the methods like
twisted.internet.utils.getProcessOutput instead.

] #
] # XML-RPC applicationLogic class
] #
] class TemperatureAccess:
[..snip..]
] #
] # Produce a form to be used to search the text repository.
] #
] def show_temperature_form(self, request):
] dbglogmsg('*** (show_search_form)')
] self.request = request
] self.content = Content_ConvertTemperatureForm
] self.request.write(self.content)
] self.request.finish()
] return NOT_DONE_YET

This is a pretty messy seperation of application logic from the XML-RPC
layer -- you're operating on a HTTPRequest object, which has nothing to do
with temperature logic. Your abstractions are leaking.

Your example here is pretty confusing. I *think* what you're doing is
having a Twisted webserver render requests based on data retrieved
dynamically via XML-RPC, but I can't see anywhere where you state that
clearly. It took me a while to figure out that TemperatureAccess was on the
XML-RPC *client* side, not the server.

I recommend trying to rewrite this example using Woven. It provides a
framework that encourages proper seperation of Models (the data structures,
whereever they come from, in this case XML-RPC) and Views (the way the model
is presented), and think it would come out much more elegantly.

I also recommend rewriting your example XML-RPC server using
twisted.web.xmlrpc.XMLRPC -- it provides a very easy way to write XML-RPC
servers, and seeing as this is a document about Twisted, it may as well use
it :) You'll probably find the example in doc/examples/xmlrpc.py to be
helpful.

Finally, for the test harness, you might want to consider re-using the
infrastructure in Twisted, rather than rolling your own. For a brief
example, I recommend the DeferredModelTestCase in
twisted/test/test_woven.py.

I hope this feedback helps.

-Andrew.
Jul 18 '05 #7

P: n/a
On Thu, 11 Sep 2003 17:19:50 -0700, Dave Kuhlman <dk******@rexx.com>
wrote:

Twisted is more than Web apps, by the way.


Does Twisted work well with Python 2.3?

-pu

Jul 18 '05 #8

P: n/a
On Fri, Sep 12, 2003 at 09:21:58AM +0200, Patrick Useldinger wrote:
On Thu, 11 Sep 2003 17:19:50 -0700, Dave Kuhlman <dk******@rexx.com>
wrote:

Twisted is more than Web apps, by the way.


Does Twisted work well with Python 2.3?


Yes, current versions support 2.3 without any problems.

-Andrew.
Jul 18 '05 #9

P: n/a
pd
How about skunkweb? I haven't used this, in fact I'm only just getting
into python at the moment. Perhaps someone with experience can comment
on this app...
To quote the site, skunkweb ... "is an extensible, scalable and easy to
use application server written in Python"

hth

Paul.
p3d AT yahoo dot co dot uk
Patrick Useldinger wrote:
Hi all,
after my unsuccessful try to run Apache 2 with mod_python and Python
2.3, I am looking for an alternative approach.
My aim is to write a small web-based application:

Python
- the solution must be based / usable on Python 2.3

Portability
Targeted plaforms are
- Windows 2000 Server
- Windows XP Pro
- AIX 5.1

Webserver:
- supporting up to 50 concurrent client connections
- must be able to use Python 2.3 to create dynamic pages
I can think of 3 alternatives to Apache:
- Medusa
- Twisted
- Zope
Which one is the easiest to work with? Which one is known to work on an
AIX 5.1 platform, for instance?

Persistent storage
- Is ZODB easily usable from outside Python, i.e. to produce reports
without reverting to programming?
- Is MySQL with Python a good combination?
Regards,
-PU


Jul 18 '05 #10

P: n/a
On Fri, 12 Sep 2003 17:33:34 +1000, Andrew Bennetts
<an***************@puzzling.org> wrote:
Does Twisted work well with Python 2.3?


Yes, current versions support 2.3 without any problems.


Version 1.0.6 refuses to install, though, complaining it requires Python
2.2.

-PU

Jul 18 '05 #11

P: n/a
On Fri, 12 Sep 2003 12:50:13 +0100, pd <p@d.com> wrote:
How about skunkweb? I haven't used this, in fact I'm only just getting
into python at the moment. Perhaps someone with experience can comment
on this app...


The homepage says it doesn't work on Win32, so it's not a good candidate
for me.
-PU

Jul 18 '05 #12

P: n/a
AOLserver:
http://www.aolserver.com/

PyWX: Python for AOLserver:
http://pywx.idyll.org/

"PyWX is a plug-in for the open source Web server AOLserver that embeds
a Python interpreter within the AOLserver process. This allows AOLserver
to execute Python scripts in response to HTTP requests in a variety of ways.

AOLserver is a high-performance, single-process/multiple-threads Web
server that is used at several high-throughput sites including AOL.com
and digitalcity.com. PyWX enables full access to the AOLserver API from
Python, as well as tying PyWX into AOLserver as an almost complete peer
to Tcl."

Unfortunately Python is not free-threading, so it is not ideal for web
server.

Harri

Patrick Useldinger wrote:
Hi all,
after my unsuccessful try to run Apache 2 with mod_python and Python
2.3, I am looking for an alternative approach.
My aim is to write a small web-based application:

Python
- the solution must be based / usable on Python 2.3

Portability
Targeted plaforms are
- Windows 2000 Server
- Windows XP Pro
- AIX 5.1

Webserver:
- supporting up to 50 concurrent client connections
- must be able to use Python 2.3 to create dynamic pages
I can think of 3 alternatives to Apache:
- Medusa
- Twisted
- Zope
Which one is the easiest to work with? Which one is known to work on an
AIX 5.1 platform, for instance?

Persistent storage
- Is ZODB easily usable from outside Python, i.e. to produce reports
without reverting to programming?
- Is MySQL with Python a good combination?
Regards,
-PU


Jul 18 '05 #13

P: n/a
On Sat, 13 Sep 2003 08:06:39 -0500, "A.M. Kuchling" <am*@amk.ca> wrote:

Quixote (www.mems-exchange.org/software/quixote, www.quixote.ca) comes with
modules to work with both Medusa and Twisted (and also AOLserver and Apache).


I'll have a look at it, thanks.
- supporting up to 50 concurrent client connections


Do you mean 50 hits per second, which is a substantial load (4 million hits
a day!) or just 50 users on the site at the same time, which is a hit every
second or two? Anything should be able to handle the latter case; I'd go
with Apache + SCGI for the former.


50 users at the same time, a very moderate load I believe.
BTW, after trying mod_pyton (KO due to Python 2.3), Twisted (idem.), I
am currently playing around with Medusa and I like it. I think I am
going into that direction. Thanks for keeping it alive.

-PU

Jul 18 '05 #14

P: n/a
[CC'ing the Twisted mailing list]

On Fri, Sep 12, 2003 at 08:05:59PM +0200, Patrick Useldinger wrote:
On Fri, 12 Sep 2003 17:33:34 +1000, Andrew Bennetts
<an***************@puzzling.org> wrote:
Does Twisted work well with Python 2.3?


Yes, current versions support 2.3 without any problems.


Version 1.0.6 refuses to install, though, complaining it requires Python
2.2.


Eek! Does 1.0.7 (just released) work any better? Also, what platform are
you using, and are you installing from the source .tar.gz or something else?

-Andrew.
Jul 18 '05 #15

P: n/a
On Sun, 14 Sep 2003 15:43:30 +1000, Andrew Bennetts
<an************@puzzling.org> wrote:

Eek! Does 1.0.7 (just released) work any better? Also, what platform are
you using, and are you installing from the source .tar.gz or something else?


I didn't try 1.0.7, didn't even know that it was out.
I am on a WinXP box and used the prebuild binaries.

I have started digging into Medusa right now... and stay focused on
that one until I have a blocking problem or I get bored ;-)

-PU

Jul 18 '05 #16

P: n/a
On Mon, Sep 15, 2003 at 08:18:25PM +0200, Patrick Useldinger wrote:
On Sun, 14 Sep 2003 15:43:30 +1000, Andrew Bennetts
<an************@puzzling.org> wrote:

Eek! Does 1.0.7 (just released) work any better? Also, what platform are
you using, and are you installing from the source .tar.gz or something else?
I didn't try 1.0.7, didn't even know that it was out.
I am on a WinXP box and used the prebuild binaries.


Ah, ok. The prebuild binaries for Windows only work on one version, and I
think the Windows maintainer has chosen to only support 2.2. You're welcome
to build your own from the source, or try to convince someone on IRC to
build 2.3 binaries for you ;)

Also, you don't need a compiler to use Twisted. The C extensions are
entirely optional, and just provide some optimisations over some of the
equivalent pure python modules, but most users would probably never notice
the difference.
I have started digging into Medusa right now... and stay focused on
that one until I have a blocking problem or I get bored ;-)


We'll be waiting ;)

-Andrew.
Jul 18 '05 #17

P: n/a
Andrew Bennetts wrote:
On Mon, Sep 15, 2003 at 08:18:25PM +0200, Patrick Useldinger wrote:

On Sun, 14 Sep 2003 15:43:30 +1000, Andrew Bennetts
<an************@puzzling.org> wrote:

Eek! Does 1.0.7 (just released) work any better? Also, what platform are
you using, and are you installing from the source .tar.gz or something else?

I didn't try 1.0.7, didn't even know that it was out.
I am on a WinXP box and used the prebuild binaries.


Ah, ok. The prebuild binaries for Windows only work on one version, and I
think the Windows maintainer has chosen to only support 2.2. You're welcome
to build your own from the source, or try to convince someone on IRC to
build 2.3 binaries for you ;)

Also, you don't need a compiler to use Twisted. The C extensions are
entirely optional, and just provide some optimisations over some of the
equivalent pure python modules, but most users would probably never notice
the difference.
I have started digging into Medusa right now... and stay focused on
that one until I have a blocking problem or I get bored ;-)

<insert clever joke about
no-"blocking"-problems-in-an-asycn-select-based-web-server here>

If you'd like to use Medusa with less digging and much less boredom, I'd
encourage you to check out the Quixote Web app framework, which runs
beautifully on Win32/Medusa (as well as a number of other front ends,
including Twisted).

Personally I think it's nice to be able to write app code against a
(lean, mean and delightful) framework, while maintaining the right to
choose and switch between a range of Web servers. That's good separation
of concerns.

Quixote has a shiny new advocacy site at http://quixote.ca/ and is
available for download at http://www.mems-exchange.org/software/quixote/ .
We'll be waiting ;)


If Patrick gives Quixote a try, you might be waiting a while. <double-wink>

Best wishes to all,

-- Graham

Jul 18 '05 #18

P: n/a
On Tue, 16 Sep 2003 11:48:21 +1000, Andrew Bennetts
<an***************@puzzling.org> wrote:
I have started digging into Medusa right now... and stay focused on
that one until I have a blocking problem or I get bored ;-)


We'll be waiting ;)


Wait no more... I am currently working my way through the Twisted doc,
now that the Python 2.3 version of Twisted is out. I spend an awful
amount of time to get a dynamic page with Medusa, specifically due to
the fact that there is no documentation except the comments in the code.

I am most impressed by Twisted.
But then, of course, you knew that already ;-)

-PU
Jul 18 '05 #19

P: n/a
On Thu, 18 Sep 2003 21:47:43 +0200,
Patrick Useldinger <p.**********@myrealbox.com> wrote:
now that the Python 2.3 version of Twisted is out. I spend an awful
amount of time to get a dynamic page with Medusa, specifically due to
the fact that there is no documentation except the comments in the code.


Note that Quixote includes support for both Medusa and Twisted; see
the modules in the quixote.server package.

--amk
Jul 18 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.