21

I am new to Python and i am not able to understand the server concepts in Python.

First of all what is WSGI and what are Wsgiref and Werkzeug and how are they different from CherryPy WSGI Server, Gunicorn, Tornado (HTTP Server via wsgi.WSGIContainer), Twisted Web, uWSGI, Waitress WSGI Server.

If i need to develop a web application from scratch, i mean starting from the beginning, where should i start, my company needs a custom framework and the application is based on critical performance overheads.

Please help and explain how they are different.

P.S I am not a beginner to programming.

Ray
  • 2,472
  • 18
  • 22
ajknzhol
  • 6,322
  • 13
  • 45
  • 72
  • wsgi is an interface between the web-server and python. Any application that conforms to WSGI can be run with any server which has a WSGI driver. It also enables you to put middleware between the web server and the application, which could for instance handle routing, session management, caching, etc. – Thayne Jan 11 '14 at 05:21

1 Answers1

25

WSGI is just a set a rules to help unify and standardize how Python applications communicate with web servers. It defines both how applications should send responses and how servers should communicate with applications and pass along the environment and other details about the request. Any application that needs to communicate with any web server implements WSGI, because its the de-facto standard and recommended method for Python. WSGI came about to unify the other implementations (CGI, mod_python, FastCGI).

wsgiref is a reference implementation of the WSGI interface. Its like a blueprint to help developers understand how to implement WSGI in their own applications.

The other things you mentioned are all different applications that implement the WSGI standard; with some exceptions:

  1. Twisted is a library to create applications that can communicate over a network. Any kind of network, and any kind of applications. Its not limited to the web.

  2. Tornado is similar to Twisted in that it is also a library for network communication; however it is designed for non blocking applications. Things that require a long open connection to the server (like say, an application that displays realtime feeds).

  3. CherryPy is a very minimal Python framework for creating web applications. It implements WSGI.

  4. Werkzeug is a library that implements WSGI. So if you are developing an application that needs to speak WSGI, you would import werkzeug because it provides all various parts of WSGI that you would need.

  5. uWSGI is a project that allows easily hosting of multiple web applications. The fact that it as WSGI in the name is because WSGI was the first plugin that was released with the application. It is perhaps the odd duck in this list because it is not a development framework, but more of a way to manage multiple web applications.

Web servers that implement WSGI can talk to any application that also implements WSGI. modwsgi is a popular implementation of WSGI for webservers; it is available for both Apache and Nginx and for IIS there is the isapi wsgi module.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • 1
    So Wsgiref is a reference implementation on WSGI and therefore we can create our own frameworks from it. am i right ? – ajknzhol Jan 11 '14 at 05:44
  • Yes, but it would be a lot easier to use a more "user friendly" toolset like werkzeug. – Burhan Khalid Jan 11 '14 at 06:50
  • @BurhanKhalid I am under the assumption that WSGI application has to be written in Python, but WSGI server can be written in any other language(i.e. modwsgi is written in C)? How does Python WSGI application works with WSGI server that is not written Python? – Quazi Irfan Sep 16 '21 at 03:19