What Is WSGI (Web Server Gateway Interface)

  1. What Is WSGI (Web Server Gateway Interface)
  2. Configuring WSGI on Ubuntu/Centos
  3. Getting Started With Flask
Reading Time: 2 minutes

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.

Web Server Gateway Interface
Requests are sent from the client's browser to the server. WSGI forwards the request to the webserver python app, which then returns the completed request back to the webserver and on to the browser

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!

Give us a call today at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable Solutions providers right away!

Series Navigation
Next Article >>
Avatar for John Long

About the Author: John Long

Latest Articles

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article