python web service or Apache?

rurpy at yahoo.com rurpy at yahoo.com
Mon Oct 26 14:48:55 EDT 2009


On 10/26/2009 08:00 AM, Peng Yu wrote:
> On Sun, Oct 25, 2009 at 11:09 PM, Simon Forman <sajmikins at gmail.com> wrote:
>> On Sun, Oct 25, 2009 at 4:47 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
>>> Although, python can be used to provide web service. The following
>>> webpage also mentioned, "Apache the best and most widely used web
>>> server on the Internet today, check it out. If you want to run your
>>> own web server this is the one to get, you can get binaries for both
>>> Windows and Unix. You can download the entire sourcecode if you want
>>> to check how it was made." Therefore, it would be better to use Apache
>>> rather than python to provide web service, right?
>>>
>>> http://fragments.turtlemeat.com/pythonwebserver.php
>>
>>
>> Both "best" and "better" (that website and you, respectively) omit
>> mention of the criteria used for the evaluation.
>>
>> To determine what is "best" you must first answer "for what?"
>>
>>
>> (Also, it is reasonable to use /both/ apache and python together, with
>> mod_python or mod_wsgi, etc...)
>
> I have never made a web server before. So I don't know what criterion
> I should use? If possible, would you please let me know what pros and
> cons you can think of?

Apache requires root access to the server machine, is quite complex
and requires some learning and work to setup and use.
On the other hand it is very powerful, will handle high traffic,
and can handle the requirements of most any web site, so even if
you start with a simple site you can be pretty sure it will handle
your needs in the future as your web site grows.  Because Apache
is widely used, there an many places and people that can provide
help and advice on how to run it.

A small simple custom web server built with Python will likely
only work well with a very small traffic volume and will have
very limited capabilities but is very quick to get up and running.
You can run it on a non-privileged port if you do not have
root access to your server machine.

> How to use apache and python together? Does each of them offer some
> functions that are not available in the other? Thank you!

Apache, like most general purpose web servers, supports the CGI
protocol.  You can setup Apache so that when a request is made
for a file ending with ".py", it will run the python file and
send the program's output to the client browser.  This allows
you to generate html output from the Python program.  Python's
standard lib contains the "cgi" module that will help in writing
python code for this.

There are other more efficient ways of using Python with
a web server such as mod_python, or wsgi, but cgi is probably
the simplest, and has the most "how-to" info available.

HTH



More information about the Python-list mailing list