Mod python
Encyclopedia
mod_python is an Apache HTTP Server
module that integrates the Python programming language
into the Apache server. It is intended to replace Common Gateway Interface
(CGI) as a method of executing Python scripts on a web server. The promised benefits are faster execution speed and maintaining data over multiple sessions. Although it is no longer actively developed, the official Apache mod_python page states: "This does not mean that it is 'dead' as some people have claimed. It simply means that the code and the project are mature enough when very little is required to maintain it."
, but it is often easier to use a specialized module to embed the desired language into the web server itself. This is exactly what mod_python is designed to do. Since the process is not terminated after the script execution like CGI, persistent data can be stored, such as database connections. This may reduce script execution overhead.
Since mod_python modules are integrated with the web server, they can do almost anything an Apache module written in C
can do: implement protocols besides HTTP, filter the request and response, determine a document's content type, etc.
Another advantage to mod_python is that it can talk directly to Apache's core system, and interface as well as actually control the heart of Apache. This is done by handlers that the programmer specifies in the Apache configuration file, and every client request directed at that specific directory will not be processed by Apache, rather by mod_python and a "Main" function that handles all requests.
Using mod_python also has the advantage of Python Server Pages
(PSP), a way to embed Python code into HTML
pages, similar to ASP
, PHP
, and JavaServer Pages
(JSP).
Additionally to the problematic embedded mode offered by Mod_python, mod wsgi
(another alternative Apache module for running Python web applications) also offers a daemon mode that is more secure and easier handled for a non-root webhosting user.
mod_python was originally written by Aaron Watters and distributed on the CD for the book "Internet Programming with Python".
The first version of mod_python as modified by Gregory Trubetskoy was released in 2000. In September 2002 mod_python was donated to the Apache Software Foundation
and became part of the Apache HTTP Server
project. The Apache Software Foundation June board meeting, which took place on June 16th 2010, unanimously passed a resolution to terminate Apache Quetzalcoatl Project (umbrella project for mod_python).
Apache HTTP Server
The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...
module that integrates the Python programming language
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
into the Apache server. It is intended to replace Common Gateway Interface
Common Gateway Interface
The Common Gateway Interface is a standard method for web servers software to delegate the generation of web pages to executable files...
(CGI) as a method of executing Python scripts on a web server. The promised benefits are faster execution speed and maintaining data over multiple sessions. Although it is no longer actively developed, the official Apache mod_python page states: "This does not mean that it is 'dead' as some people have claimed. It simply means that the code and the project are mature enough when very little is required to maintain it."
Benefits
Ordinary CGI execution starts a new process every time a connection is made to a script on the server. This works well in low to medium traffic sites, but does not scale well when used on a high traffic site. There are methods of enhancing the performance of CGI, such as FastCGIFastCGI
FastCGI is a protocol for interfacing interactive programs with a web server. FastCGI is a variation on the earlier Common Gateway Interface ; FastCGI's main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page...
, but it is often easier to use a specialized module to embed the desired language into the web server itself. This is exactly what mod_python is designed to do. Since the process is not terminated after the script execution like CGI, persistent data can be stored, such as database connections. This may reduce script execution overhead.
Since mod_python modules are integrated with the web server, they can do almost anything an Apache module written in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
can do: implement protocols besides HTTP, filter the request and response, determine a document's content type, etc.
Another advantage to mod_python is that it can talk directly to Apache's core system, and interface as well as actually control the heart of Apache. This is done by handlers that the programmer specifies in the Apache configuration file, and every client request directed at that specific directory will not be processed by Apache, rather by mod_python and a "Main" function that handles all requests.
Using mod_python also has the advantage of Python Server Pages
Python Server Pages
Python Server Pages is a name used by several different implementations of server-side script engines for creating dynamically-generated web pages by embedding Python in HTML...
(PSP), a way to embed Python code into HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
pages, similar to ASP
Active Server Pages
Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated Web pages. Initially released as an add-on to Internet Information Services via the Windows NT 4.0 Option Pack Active Server Pages (ASP), also known as Classic...
, PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
, and JavaServer Pages
JavaServer Pages
JavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...
(JSP).
Problems
Embedding the Python interpreter (and different Python applications) directly into the Apache process is not without problems, especially when looking at shared Python web application hosting:- all hosted applications run under the same uid/gid (bad for security and separation of different users' web applications)
- restarting Apache (usually needs root user privileges) might be necessary:
- if some Python code malfunctions
- in case of memory leaks
- after a user upgraded their Python code
Additionally to the problematic embedded mode offered by Mod_python, mod wsgi
Mod wsgi
mod_wsgi is an Apache HTTP Server module by Graham Dumpleton that provides a WSGI compliant interface for hosting Python 2.3+ based web applications under Apache. As of version 3.0, mod_wsgi supports Python 2.6 and 3.1...
(another alternative Apache module for running Python web applications) also offers a daemon mode that is more secure and easier handled for a non-root webhosting user.
History
The initial implementation ofmod_python was originally written by Aaron Watters and distributed on the CD for the book "Internet Programming with Python".
The first version of mod_python as modified by Gregory Trubetskoy was released in 2000. In September 2002 mod_python was donated to the Apache Software Foundation
Apache Software Foundation
The Apache Software Foundation is a non-profit corporation to support Apache software projects, including the Apache HTTP Server. The ASF was formed from the Apache Group and incorporated in Delaware, U.S., in June 1999.The Apache Software Foundation is a decentralized community of developers...
and became part of the Apache HTTP Server
Apache HTTP Server
The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...
project. The Apache Software Foundation June board meeting, which took place on June 16th 2010, unanimously passed a resolution to terminate Apache Quetzalcoatl Project (umbrella project for mod_python).
See also
- Apache HTTP ServerApache HTTP ServerThe Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...
- PythonPython (programming language)Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
- mod wsgiMod wsgimod_wsgi is an Apache HTTP Server module by Graham Dumpleton that provides a WSGI compliant interface for hosting Python 2.3+ based web applications under Apache. As of version 3.0, mod_wsgi supports Python 2.6 and 3.1...
- mod jkMod jkmod_jk is the connector used to connect the Tomcat servlet container with web servers such as Apache, Netscape, iPlanet, SunOne and even IIS using the AJP protocol.In a nutshell, a web server is waiting for client HTTP requests...
- mod perlMod perlmod_perl is an optional module for the Apache HTTP server. It embeds a Perl interpreter into the Apache server, so that dynamic content produced by Perl scripts can be served in response to incoming requests, without the significant overhead of re-launching the Perl interpreter for each request...
- mod parrotMod parrotmod_parrot is an optional module for the Apache web server. It embeds a Parrot virtual machine interpreter into the Apache server and provides access to the Apache API to allow handlers to be written in Parrot assembly language, or any high-level language targeted to Parrot....
- SpyceSpyceSpyce is technology similar to PHP that can be used to embed Python code into webpages. Spyce is free software, distributed under a BSD-style licence, with some additional restrictions about documentation notices.-Common Spyce Embedding Methods:...