tags:

views:

442

answers:

5

Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why.

So why should I switch to it? What are the benefits? Is it hard, and is the learning curve worth it?

+1  A: 

You shouldn't have to relearn much, since the difference from a developer perspective is just a small wrapper and some server configuration.

From a deployment perspective, the difference is that your python code lives in a separate process from the web browser, which means

a) The python process can be running as another user than the web server. This can be valuable for security, if used right.

b) The web server processes does not need to contain the python runtime. This can be a major boost for performance if the server runs a lot of "other" requests (static files, etc) and some heavy python requests.

Rasmus Kaj
Both a) and b) have nothing to do with WSGI, you can do it with plain SCGI/FastCGI/AJP as well.
PiotrLegnica
Well, I used mod_python, so I guess his anwser is useful.
e-satis
You can run WSGI apps with mod_python.
PiotrLegnica
Well, yes. My answer concerned the difference between wsgi (used in a normal way) and mod_pyton (used in a normal way), since I gathered that was the question was about.
Rasmus Kaj
Really, so should I stick to mod_python or use mod_wsgi, if I give a try to wsgi?
e-satis
In relation to mod_wsgi, (b) is wrong. In mod_wsgi the web server processes do still contain the Python run time. Its presence does not affect performance of static requests or requests for other language modules.
Graham Dumpleton
A: 

WSGI is the standard API, which enables you to choose the webserver, and also put A WSGI pipeline such as Repoze in front of it.

See http://repoze.org/

Lennart Regebro
+2  A: 

Most Python frameworks implement wsgi. There is mod_wsgi for apache and a SCGI/FastCGI/AJP module + Flup for the others. That way you can have all the advantages of a separate Python process, without being tied to one webserver.

THC4k
+3  A: 

For developing sophisticated web applications in Python, you would probably use a more comprehensive web development framework like DJango, Zope, Turbogears etc. As an application developer, you don't have to worry about WSGI much. All you have to be aware about is that these frameworks support WSGI. The WSGI allows separation of web server and web application code and a system administrator can change the web server as long as the web application is WSGI compliant. If you are developing in one of these frameworks, you would anyway be satisfying this condition.

If you are a web framework developer (that is developing DJango or Zope itself), then you have to understand WSGI in more depth.

Shailesh Kumar
+4  A: 

mod_wsgi vs. mod_python:

  • mod_wsgi is a little faster (internally there's more C, less Python)
  • mod_wsgi processes can be isolated from Apache, which improves security/stability with lower memory use[1]
  • mod_python gives you access to some of Apache's internals

WSGI in general:

  • lots of reusable middleware (authentication/authorisation, session stuff, caching, filtering)
  • ease of deployment on non-Apache webservers either via native WSGI support or flup

[1] - compared to a preforking Apache, which maintains a separate Python interpreter in each process

SimonJ