Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Background  





2 Specification overview  





3 WSGI middleware  





4 Examples  



4.1  Example application  





4.2  Example of calling an application  







5 WSGI-compatible applications and frameworks  





6 See also  





7 References  





8 External links  














Web Server Gateway Interface






العربية
Čeština
Deutsch
Español
فارسی
Français

Italiano
עברית
Nederlands

Português
Русский
Türkçe
Українська

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


The Web Server Gateway Interface (WSGI, pronounced whiskey[1][2]orWIZ-ghee[3]) is a simple calling convention for web servers to forward requests to web applicationsorframeworks 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[edit]

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[edit]

The WSGI has two sides:

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[edit]

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]

Examples[edit]

Example application[edit]

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:

Example of calling an application[edit]

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[edit]

Numerous web frameworks support WSGI:

  • 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]
  • Tornado
  • Trac
  • TurboGears
  • Uliweb[20]
  • uWSGI
  • Waitress[21]
  • web.py[22]
  • web2py
  • weblayer[23]
  • Werkzeug[24]
  • Radicale[25]
  • Currently wrappers are available for FastCGI, CGI, SCGI, AJP (using flup), twisted.web, Apache (using mod_wsgiormod_python), Nginx (using ngx_http_uwsgi_module),[26] Nginx Unit (using the Python language module),[27] and Microsoft IIS (using WFastCGI,[28] isapi-wsgi,[29] PyISAPIe,[30] or an ASP gateway).

    See also[edit]

    References[edit]

    1. ^ Simionato, Michele (June 11, 2007). "An Introduction to Web Programming with WSGI".
  • ^ Edge, Jake (July 9, 2019). "Mucking about with microframeworks". LWN.
  • ^ Goldberg, Kevin (2016-05-09). "An Introduction to Python WSGI Servers for Performance | AppDynamics". Application Performance Monitoring Blog | AppDynamics. Retrieved 2020-08-20.
  • ^ a b "PEP 3333 - Python Web Server Gateway Interface v1.0.1". Python.org. Retrieved 2018-04-04.
  • ^ "PEP 333 -- Python Web Server Gateway Interface v1.0". Python.org. Retrieved 2018-04-04.
  • ^ "FrontPage - Python Wiki". Python.org. Retrieved 2017-01-27.
  • ^ a b "PEP 3333 -- Python Web Server Gateway Interface v1.0.1". Python.org. Retrieved 2018-04-04.
  • ^ i.e. "a function, method, class, or an instance with a __call__ method"
  • ^ "PEP 3333 -- Python Web Server Gateway Interface v1.0.1". Python.org. Retrieved 2018-04-04.
  • ^ "Creating WSGI Middleware - Alan Christopher Thomas - Minted - PythonKC". YouTube. 2015-08-28. Archived from the original on 2021-12-12. Retrieved 2017-01-27.
  • ^ "プエラリアジェルの効果は?". Bobo.digicool.com. Retrieved 2017-01-27.
  • ^ "Django without mod_python, and WSGI support | Weblog | Django". Djangoproject.com. 2005-07-18. Retrieved 2017-01-27.
  • ^ "wsgi – WSGI server — Eventlet 0.20.1 documentation". Eventlet.net. Retrieved 2017-01-27.
  • ^ "Falcon - Bare-metal web API framework for Python". Retrieved 2017-10-22.
  • ^ "gevent-fastcgi 1.0.2.1 : Python Package Index". Pypi.python.org. 2015-12-06. Retrieved 2017-01-27.
  • ^ "anomaly/prestans: A WSGI compliant REST micro-framework". GitHub.com. Retrieved 2017-01-27.
  • ^ "Google Code Archive - Long-term storage for Google Code Project Hosting". Code.google.com. Retrieved 2017-01-27.
  • ^ "Pycnic Framework". Pycnic.nullism.com. Retrieved 2017-01-27.
  • ^ "theintencity/restlite: Light-weight RESTful server tools in Python". GitHub.com. Retrieved 2017-01-27.
  • ^ "limodou/uliweb: Simple and easy use python web framework". GitHub.com. Retrieved 2017-01-27.
  • ^ "waitress documentation". docs.pylonsproject.org. Retrieved 2018-09-26.
  • ^ "Welcome to". Web.py. 2009-09-11. Retrieved 2017-01-27.
  • ^ "weblayer — weblayer v0.4.3 documentation". Packages.python.org. Retrieved 2017-01-27.
  • ^ "Welcome | Werkzeug (The Python WSGI Utility Library)". Werkzeug.pocoo.org. Retrieved 2017-01-27.
  • ^ "CalDAV and CardDAV Server - A Simple Calendar and Contact Server". Radicale.org. Retrieved 2017-01-27.
  • ^ "Module ngx_http_uwsgi_module". Nginx.org. Retrieved 2017-01-27.
  • ^ "Configuration — NGINX Unit". Unit.nginx.org. Retrieved 2023-05-04.
  • ^ "Python Tools for Visual Studio - Documentation". Pytools.codeplex.com. Retrieved 2017-01-27.
  • ^ "Google Code Archive - Long-term storage for Google Code Project Hosting". Code.google.com. Retrieved 2017-01-27.
  • ^ "Python ISAPI Extension for IIS download | SourceForge.net". Pyisapie.sourceforge.net. 2012-04-24. Retrieved 2017-01-27.
  • External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Web_Server_Gateway_Interface&oldid=1153125256"

    Category: 
    Python (programming language)
    Hidden categories: 
    Articles with short description
    Short description matches Wikidata
    Articles with too many examples from September 2018
    All articles with too many examples
    Wikipedia articles with style issues from September 2018
     



    This page was last edited on 4 May 2023, at 10:30 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki