Sponsored Links

Selasa, 26 Desember 2017

Sponsored Links

A Detailed Study of WSGI - Web Server Gateway Interface of Python
src: www.cabotsolutions.com

The Web Server Gateway Interface (WSGI) is a specification for simple and universal interface between web servers and web applications or frameworks for the Python programming language. It was originally specified in PEP 333 authored by Phillip J. Eby, and published on 7 December 2003. It has since been adopted as a standard for Python web application development. The latest version of the specification is v1.0.1, also known as PEP 3333, published on 26 September 2010.


Video Web Server Gateway Interface



Background

Python web frameworks had been a problem for new Python users since the choice of web framework would limit the choice of usable web servers, and vice versa. Python applications were often designed for only one of CGI, FastCGI, mod_python, or some other custom API of a specific web server.

WSGI was created as a low-level interface between web servers and web applications or frameworks to promote common ground for portable web application development.


Maps Web Server Gateway Interface



Specification overview

The WSGI has two sides: the "server" or "gateway" side (often a web server such as Apache or Nginx), and the "application" or "framework" side (the Python script itself). To process a WSGI request, the server side executes the application and provides environment information and a callback function to the application side. The application processes the request, returning the response to the server side using the callback function it was provided.

Between the server and the application, there may be a WSGI middleware, which implements both sides of the API. The server receives a request from a client and forwards it to the middleware. After processing, it sends a request to the application. The application's response is forwarded by the middleware to the server and ultimately to the client. There may be multiple middlewares forming a stack of WSGI-compliant applications.

A "middleware" component can perform such functions as:

  • Routing a request to different application objects based on the target URL, after changing the environment variables accordingly.
  • Allowing multiple applications or frameworks to run side-by-side in the same process
  • Load balancing and remote processing, by forwarding requests and responses over a network
  • Performing content post-processing, such as applying XSLT stylesheets

cgi.jpg
src: java2success.com


Examples

Example application

A WSGI-compatible "Hello, World" application written in Python:

Where:

  • Line 1 defines a callable named application, which takes two parameters, environ and start_response. environ is a dictionary containing environment variables in CGI. start_response is a callable taking two required parameters status and response_headers.
  • Line 2 calls start_response, specifying "200 OK" as the status and a "Content-Type" header.
  • Line 3 returns the body of the response as a string literal.

Example of calling an application

An example of calling an application and retrieving its response. A web server gives a callback start_response to a web framework application. A start_response has an http protocol status, headers, and body. For Django, an HttpResponse object is returned. The "environ" fragment consists of, for example, REQUEST_METHOD info. Depending on this info, it might or might not call ("OPTIONS") this app.


Web Engineering An introduction. Motivation The World Wide Web is ...
src: images.slideplayer.com


WSGI-compatible applications and frameworks

Numerous web frameworks support WSGI:


Currently wrappers are available for FastCGI, CGI, SCGI, AJP (using flup), twisted.web, Apache (using mod_wsgi or mod_python), Nginx (using ngx_http_uwsgi_module), and Microsoft IIS (using WFastCGI, isapi-wsgi, PyISAPIe, or an ASP gateway).


Siebel Architecture and Servers รข€
src: siebeloracle.wordpress.com


WSGI and Python 3

The separation of binary and text data in Python 3 poses a problem for WSGI, as it specifies that header data should be strings, while it sometimes needs to be binary and sometimes text. This works in Python 2 where text and binary data both are kept in "string" variables, but in Python 3 binary data is kept in "bytes" variables and "string" variables are for unicode text data. An updated version of the WSGI specification that deals with this is PEP 3333.

A reworked WSGI spec Web3 has also been proposed, specified in PEP444. This standard is an incompatible derivative of WSGI designed to work on Python 2.6, 2.7, 3.1+.


1/16 Steven Leung Introduction to HTML/CGI/JavaScript Intro to ...
src: images.slideplayer.com


See also

  • Rack - Ruby web server interface
  • PSGI - Perl Web Server Gateway Interface
  • SCGI - Simple Common Gateway Interface
  • JSGI - JavaScript web server gateway interface

Modbus TCP/IP to IEC 60870-5-104 Server Gateway - ProSoft ...
src: prosoft-technology.com


References


Vrije Universiteit amsterdamPostacademische Cursus Informatie ...
src: images.slideplayer.com


External links

  • PEP 333 - Python Web Server Gateway Interface
  • PEP 3333 - Python Web Server Gateway Interface v1.0.1
  • WSGI metaframework
  • Comprehensive wiki about everything WSGI
  • WSGI Tutorial
  • Python standard library module wsgiref
  • Getting Started with WSGI
  • NWSGI - .NET implementation of the Python WSGI specification for IronPython and IIS
  • Gevent-FastCGI server implemented using gevent coroutine-based networking library

Source of the article : Wikipedia

Comments
0 Comments