Web Server Gateway Interface: Difference between revisions
imported>William Avery |
imported>SchlurcherBot m Bot: http → https |
||
| Line 97: | Line 97: | ||
* [[mod_wsgi]] for use with [[Apache (web server)|Apache]]<ref>{{cite web|url=http://code.google.com/p/modwsgi/ |title=Google Code Archive - Long-term storage for Google Code Project Hosting |website=Code.google.com |access-date=2017-01-27}}</ref> | * [[mod_wsgi]] for use with [[Apache (web server)|Apache]]<ref>{{cite web|url=http://code.google.com/p/modwsgi/ |title=Google Code Archive - Long-term storage for Google Code Project Hosting |website=Code.google.com |access-date=2017-01-27}}</ref> | ||
* netius | * netius | ||
* pycnic<ref name="pycnic">{{cite web|url= | * pycnic<ref name="pycnic">{{cite web|url=https://pycnic.nullism.com |title=Pycnic Framework |website=Pycnic.nullism.com |access-date=2017-01-27}}</ref> | ||
* [[Python Paste|Paste]] component WebOb is specifically a WSGI extension. It was adopted by the [[Pylons project]]. | * [[Python Paste|Paste]] component WebOb is specifically a WSGI extension. It was adopted by the [[Pylons project]]. | ||
* [[Pylons project|Pylons]] | * [[Pylons project|Pylons]] | ||
* [[Pyramid (web framework)|Pyramid]] | * [[Pyramid (web framework)|Pyramid]] | ||
* restlite<ref name="restlite">{{cite web|url=https://github.com/theintencity/restlite |title=theintencity/restlite: Light-weight RESTful server tools in Python |website=GitHub.com |access-date=2017-01-27}}</ref> | * restlite<ref name="restlite">{{cite web|url=https://github.com/theintencity/restlite |title=theintencity/restlite: Light-weight RESTful server tools in Python |website=GitHub.com |access-date=2017-01-27}}</ref> | ||
* Socketify<ref name="Socketify">{{cite web|url=https://github.com/cirospaciari/socketify.py |title=Socketify: Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3 |website=GitHub.com |access-date=2025-08-12}}</ref> | |||
* [[Tornado (web server)|Tornado]] | * [[Tornado (web server)|Tornado]] | ||
* [[Trac]] | * [[Trac]] | ||
| Line 108: | Line 109: | ||
* [[uWSGI]] | * [[uWSGI]] | ||
* Waitress<ref name="waitress">{{cite web|url=https://docs.pylonsproject.org/projects/waitress/en/latest/ |title=waitress documentation |website=docs.pylonsproject.org |access-date=2018-09-26}}</ref> | * Waitress<ref name="waitress">{{cite web|url=https://docs.pylonsproject.org/projects/waitress/en/latest/ |title=waitress documentation |website=docs.pylonsproject.org |access-date=2018-09-26}}</ref> | ||
* [[web.py]]<ref name="web.py">{{cite web|url= | * [[web.py]]<ref name="web.py">{{cite web|url=https://webpy.org/ |title=Welcome to |website=Web.py |date=2009-09-11 |access-date=2017-01-27}}</ref> | ||
* [[web2py]] | * [[web2py]] | ||
* weblayer<ref name="weblayer">{{cite web|url= | * weblayer<ref name="weblayer">{{cite web|url=https://packages.python.org/weblayer |title=weblayer — weblayer v0.4.3 documentation |website=Packages.python.org |access-date=2017-01-27}}</ref> | ||
* Werkzeug<ref name="Werkzeug">{{cite web|url=http://werkzeug.pocoo.org/ |title=Welcome | Werkzeug (The Python WSGI Utility Library) |website=Werkzeug.pocoo.org |access-date=2017-01-27}}</ref> | * Werkzeug<ref name="Werkzeug">{{cite web|url=http://werkzeug.pocoo.org/ |title=Welcome | Werkzeug (The Python WSGI Utility Library) |website=Werkzeug.pocoo.org |access-date=2017-01-27}}</ref> | ||
* Radicale<ref name="Radicale">{{cite web|url= | * Radicale<ref name="Radicale">{{cite web|url=https://radicale.org/ |title=CalDAV and CardDAV Server - A Simple Calendar and Contact Server |website=Radicale.org |access-date=2017-01-27}}</ref> | ||
{{div col end}} | {{div col end}} | ||
Currently wrappers are available for [[FastCGI]], [[Common Gateway Interface|CGI]], [[SCGI]], [[Apache JServ Protocol|AJP]] (using flup), [[Twisted (software)|twisted.web]], Apache (using [[mod_wsgi]] or [[mod_python]]), [[Nginx]] (using ngx_http_uwsgi_module),<ref>{{cite web|url= | Currently wrappers are available for [[FastCGI]], [[Common Gateway Interface|CGI]], [[SCGI]], [[Apache JServ Protocol|AJP]] (using flup), [[Twisted (software)|twisted.web]], Apache (using [[mod_wsgi]] or [[mod_python]]), [[Nginx]] (using ngx_http_uwsgi_module),<ref>{{cite web|url=https://nginx.org/en/docs/http/ngx_http_uwsgi_module.html |title=Module ngx_http_uwsgi_module |website=Nginx.org |access-date=2017-01-27}}</ref> [[Nginx#Nginx Unit|Nginx Unit]] (using the Python language module),<ref>{{cite web|url=https://unit.nginx.org/configuration/#python |title=Configuration — NGINX Unit |website=Unit.nginx.org |access-date=2023-05-04}}</ref> and [[Internet Information Services|Microsoft IIS]] (using WFastCGI,<ref>{{cite web|url=https://pytools.codeplex.com/wikipage?title=wfastcgi |title=Python Tools for Visual Studio - Documentation |website=Pytools.codeplex.com |access-date=2017-01-27}}</ref> isapi-wsgi,<ref>{{cite web|url=http://code.google.com/p/isapi-wsgi/ |title=Google Code Archive - Long-term storage for Google Code Project Hosting |website=Code.google.com |access-date=2017-01-27}}</ref> PyISAPIe,<ref>{{cite web|url=https://pyisapie.sourceforge.net/ |title=Python ISAPI Extension for IIS download | SourceForge.net |website=Pyisapie.sourceforge.net |date=2012-04-24 |access-date=2017-01-27}}</ref> or an [[Active Server Pages|ASP]] gateway). | ||
==See also== | ==See also== | ||
| Line 132: | Line 133: | ||
* [http://www.pythonpaste.org/ WSGI metaframework] | * [http://www.pythonpaste.org/ WSGI metaframework] | ||
* [http://www.wsgi.org/ Comprehensive wiki about everything WSGI] | * [http://www.wsgi.org/ Comprehensive wiki about everything WSGI] | ||
* [ | * [https://wsgi.tutorial.codepoint.net/ WSGI Tutorial] | ||
* [https://docs.python.org/library/wsgiref.html Python standard library module wsgiref] | * [https://docs.python.org/library/wsgiref.html Python standard library module wsgiref] | ||
* [ | * [https://lucumr.pocoo.org/2007/5/21/getting-started-with-wsgi/ Getting Started with WSGI] | ||
* [http://nwsgi.codeplex.com/ NWSGI] – .NET implementation of the Python WSGI specification for IronPython and IIS | * [http://nwsgi.codeplex.com/ NWSGI] {{Webarchive|url=https://web.archive.org/web/20131027092821/http://nwsgi.codeplex.com/ |date=2013-10-27 }} – .NET implementation of the Python WSGI specification for IronPython and IIS | ||
* [http://pypi.python.org/pypi/gevent-fastcgi Gevent-FastCGI server implemented using gevent coroutine-based networking library] | * [http://pypi.python.org/pypi/gevent-fastcgi Gevent-FastCGI server implemented using gevent coroutine-based networking library] | ||
Latest revision as of 13:09, 31 December 2025
Template:Short description Script error: No such module "redirect hatnote".
<templatestyles src="Template:TOC_right/styles.css" />
The Web Server Gateway Interface (WSGI, pronounced whiskey[1][2] or Script error: No such module "Respell".[3]) 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.[4]
WSGI was originally specified as PEP-333 in 2003.[5] PEP-3333, published in 2010, updates the specification for Python 3.
Background
In 2003, Python web frameworks were typically written against only CGI, FastCGI, mod_python, or some other custom API of a specific web server.[6] To quote PEP 333:
Python currently boasts a wide variety of web application frameworks, such as Zope, Quixote, Webware, SkunkWeb, PSO, and Twisted Web -- to name just a few. This wide variety of choices can be a problem for new Python users, because generally speaking, their choice of web framework will limit their choice of usable web servers, and vice versa... By contrast, although Java has just as many web application frameworks available, Java's "servlet" API makes it possible for applications written with any Java web application framework to run in any web server that supports the servlet API.
WSGI was thus created as an implementation-neutral interface between web servers and web applications or frameworks to promote common ground for portable web application development.[4]
Specification overview
The WSGI has two sides:
- the server/gateway side. This is often running full web server software such as Apache or Nginx, or is a lightweight application server that can communicate with a webserver, such as flup.
- the application/framework side. This is a Python callable, supplied by the Python program or framework.
Between the server and the application, there may be one or more WSGI middleware components, which implement both sides of the API, typically in Python code.
WSGI does not specify how the Python interpreter should be started, nor how the application object should be loaded or configured, and different frameworks and webservers achieve this in different ways.
WSGI middleware
A WSGI middleware component is a Python callable that is itself a WSGI application, but may handle requests by delegating to other WSGI applications. These applications can themselves be WSGI middleware components.[7]
A middleware component can perform such functions as:[7]
- 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
Examples
Example application
A WSGI-compatible "Hello, World!" application written in Python:
def application(environ, start_response):
start_response("200 OK", [("Content-Type", "text/plain")])
yield b"Hello, World!\n"
Where:
- Line 1 defines a function[8] named
application, which takes two parameters,environandstart_response.environis a dictionary containing CGI environment variables as well as other request parameters and metadata under well-defined keys.[9]start_responseis a callable itself, taking two positional parameters,statusandresponse_headers. - Line 2 calls
start_response, specifying "200 OK" as the HTTP status and a "Content-Type" response header. - Line 3 makes the function into a generator. The body of the response is returned as an iterable of byte strings.
Example of calling an application
A full example of a WSGI network server is outside the scope of this article. Below is a sketch of how one would call a WSGI application and retrieve its HTTP status line, response headers, and response body, as Python objects.[10] Details of how to construct the environ dict have been omitted.
from io import BytesIO
def call_application(app, environ):
status = None
headers = None
body = BytesIO()
def start_response(rstatus, rheaders):
nonlocal status, headers
status, headers = rstatus, rheaders
app_iter = app(environ, start_response)
try:
for data in app_iter:
assert (
status is not None and headers is not None
), "start_response() was not called"
body.write(data)
finally:
if hasattr(app_iter, "close"):
app_iter.close()
return status, headers, body.getvalue()
environ = {...} # "environ" dict
status, headers, body = call_application(app, environ)
WSGI-compatible applications and frameworks
Template:Example farm Numerous web frameworks support WSGI:
<templatestyles src="Div col/styles.css"/>
- bjoern
- BlueBream
- bobo[11]
- Bottle
- CherryPy
- Django[12]
- Eventlet[13]
- FastWSGI
- Flask
- Falcon (web framework)[14]
- Gevent-FastCGI[15]
- Google App Engine's webapp2
- Gunicorn
- prestans[16]
- mod_wsgi for use with Apache[17]
- netius
- pycnic[18]
- Paste component WebOb is specifically a WSGI extension. It was adopted by the Pylons project.
- Pylons
- Pyramid
- restlite[19]
- Socketify[20]
- Tornado
- Trac
- TurboGears
- Uliweb[21]
- uWSGI
- Waitress[22]
- web.py[23]
- web2py
- weblayer[24]
- Werkzeug[25]
- Radicale[26]
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),[27] Nginx Unit (using the Python language module),[28] and Microsoft IIS (using WFastCGI,[29] isapi-wsgi,[30] PyISAPIe,[31] or an ASP gateway).
See also
- Asynchronous Server Gateway Interface (ASGI) – The spiritual successor to WSGI, adding support for asynchronous applications
- Rack – Ruby web server interface
- PSGI – Perl Web Server Gateway Interface
- SCGI – Simple Common Gateway Interface
- JSGI – JavaScript web server gateway interface
References
<templatestyles src="Reflist/styles.css" />
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "Citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ a b Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ a b Script error: No such module "citation/CS1".
- ↑ i.e. "a function, method, class, or an instance with a
__call__method" - ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".Template:Cbignore
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
Script error: No such module "Check for unknown parameters".
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 Template:Webarchive – .NET implementation of the Python WSGI specification for IronPython and IIS
- Gevent-FastCGI server implemented using gevent coroutine-based networking library
Template:Python (programming language) Script error: No such module "navbox".