Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use WSGI?

Tags:

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?

like image 960
e-satis Avatar asked Nov 28 '09 18:11

e-satis


People also ask

Why do I need WSGI for Flask?

Flask is a fantastic micro web framework for Python, however, it is not a native web language. So to get our Python code running on a web server is tricky. Apache will use WSGI file to access our Flask application, so the WSGI file allows Apache to interact with Python as if it is native.

What is the use of WSGI in Django?

Django's primary deployment platform is WSGI, the Python standard for web servers and applications. Django's startproject management command sets up a minimal default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use.

Is WSGI only for Python?

The Web Server Gateway Interface (WSGI, pronounced whiskey or WIZ-ghee) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, version 1.0. 1, is specified in Python Enhancement Proposal (PEP) 3333.

Is asgi better than WSGI?

ASGI is a spiritual successor to WSGI, the long-standing Python standard for compatibility between web servers, frameworks, and applications. WSGI succeeded in allowing much more freedom and innovation in the Python web space, and ASGI's goal is to continue this onward into the land of asynchronous Python.


2 Answers

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.

like image 176
Shailesh Kumar Avatar answered Oct 31 '22 03:10

Shailesh Kumar


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

like image 32
SimonJ Avatar answered Oct 31 '22 02:10

SimonJ