What Is WSGI?
Have you ever wondered how Python web applications work on an Apache or NGINX web server? The answer is WSGI or Web Server Gateway Interface.
Python is rapidly gaining in popularity for various web applications and software options. WSGI is one of the numerous powerful frameworks that are enabling this forward-looking acceptance. You may be new to Python web applications and wondering how this type of application is deployed in a production environment or you may have already used this type of framework previously, but want to know more about what WSGI is.
Purpose
WSGI stands for "Web Server Gateway Interface". It is used to forward requests from a web server (such as Apache or NGINX) to a backend Python web application or framework. From there, responses are then passed back to the webserver to reply to the requestor.
Components
Most Python frameworks include a basic development server that can be used while building your web application. When you are ready to go live from a staging to a production environment, most deployments will utilize WSGI. The Python Web Server Gateway Interface specification is described in depth in PEP 3333.
There are two primary components of WSGI; The first is server-side. The server-side element is going to invoke a callable object that is usually defined by a route. Once invoked, the second component, the web application or framework, contains the structure and the code that is to be executed. In a framework such as Flask, routes are defined with a decorator.
Example
The Flask example below is what the callable object would look like for WSGI. When a request is made for this URI, the webserver passes this to WSGI which would then match the URI to a route defined in the application. The code related to that route is then executed.
# Route decorator used to define the callable object for WSGI
@app.route("/contact-us")
def contact_us():
Return "How to contact us"
Get Started Today!
With the popularity of the Python programming language growing daily, being able to utilize and employ technologies like WSGI and many other pythons apps allow you to take full advantage of these options right now!
Related Articles:
About the Author: John Long
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Clone a Drupal Site to Another Domain
Read ArticleTop Eight Virtualization Security Issues and Risks
Read ArticleAccessing Man Pages on Ubuntu 16.04 LTS
Read ArticlePremium Business Email Pricing FAQ
Read ArticleMicrosoft Exchange Server Security Update
Read Article