Web Server and Web app - csrgxtu/Cocoa GitHub Wiki

In Python Web development, you need to know what is Web server and what is Web application, what's the difference?

Why need it?

In late 1990s, to enable running Python script through web server like Apache, a programmer named Grisha Trubetskoy came up with mod_python, it loads the Python interpreter into the Apache, when a request comes, will use this interpreter execute the Python script accordingly. but this have some drawbacks:

  • when you want to use Nginx or LightHttpd as your web server, mod_python and your script wont work unless you change it accordingly.
  • Apache is multi-threading, thus it still loads too much interpreter into memory.

To make things more convinient and comfortable for Python web developers, community comes up with WSGI, a protocol between web server and web application. to support this, both web server and web application should implement in their own side.

What is WSGI?

WSGI -- web server gateway interface, is a standard protocol between web server and web application. this is the PEP333 said:

WSGI specifies a proposed standard interface between web servers and Python web applications or frameworks, to promote web application portability across a variety of web servers.

What is Web server?

A web server is a software that relays request and response through HTTP protocol. when a browser request a resource, web server will relay it to the real application to process it, when process done, will relay the response back to browser.
It didn't assemble your response, instead it should be done by web applications. there web servers includes: Gunicore, mod_wsgi, twist, tornado, cherry, wsgiref etc

What is Web app?

A web application is a long running process that accept the request from web server, process the request accordingly, and then assemble the response and send it back to web server.
Normally, most Python web development tasks appearing in the web applications.
By using the frameworks or tools, developers don't need to concern the WSGI compatible problems. just write your logical code. these frameworks and tools include: Django, Flask, Web.py etc.