Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7638401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:10:06+00:00 2026-05-31T08:10:06+00:00

I have an almost complete simple web app written as a Python CGI script.

  • 0

I have an almost complete simple web app written as a Python CGI script. I would like to change it to use WSGI, but I can’t find documentation that helps me make sense of what WSGI actually is (one only repeatedly finds calls with start_response etc. but there doesn’t seem to be much explanation fo rwhat these calls actually do). Can someone point me to a good explanation, plus a how-to on using WSGI?

Edit: Should add that I’ve seen this question but the answers still don’t seem to tell one how to use WSGI in a direct script (as opposed to in a framework).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:10:07+00:00Added an answer on May 31, 2026 at 8:10 am

    WSGI is PEP 333 (and PEP3333 for Python 3), a.k.a. Web Server Gateway Interface. It has three parts, but the part you’re interested in is how you write a WSGI application. And WSGI app is a callable object that takes two arguments and returns an iterable object (or is a generator).

    # this is my_app module
    def app(environ, start_response):
        # environ is dict-like object containing the WSGI environment
        # refer to the PEP for details
    
        # start_response is a callable that, well, starts the response
        headers = [('Content-Type', 'text/plain; charset=utf-8')]
        start_response('200 OK', headers)
    
        return ["I'm a WSGI application.\n"]
    

    To run the application, you need another part of WSGI, which is gateway. In the standard library you’ll find wsgiref package. It contains a CGI gateway:

    #!/usr/bin/python
    # this is a CGI script that runs a WSGI application inside CGI handler
    from wsgiref.handlers import CGIHandler
    from my_app import app
    CGIHandler().run(app)
    

    And also a simple HTTP server for development:

    from wsgiref.simple_server import make_server
    from my_app import app
    httpd = make_server('localhost', 8000, app)
    httpd.serve_forever()
    

    As you can see, WSGI allows you to reuse your application in different environments — CGI, SCGI, FastCGI, mod_wsgi, mod_python, etc., without actually rewriting it.

    The last part of WSGI is middleware — basically, it’s a concept that allows you to combine different WSGI applications. It forms sort of a sandwich — request flows from the top (the gateway) to the bottom (which is usually your application), with some intermediate layers in between, that might implement stuff like database connection pooling or sessions. wsgiref contains one such middleware — wsgiref.validate.validator, which checks whether layers below and above it conforms to the rules of WSGI spec.

    And that’s basically it. Now go use a framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some development skills, like refactoring operations, feel like they have an almost unlimited pontential
I have a very cluttered code, and the current revision is almost complete, meaning
I would like to use Sinatra's Streaming capability introduced in 1.3 coupled with some
My project that I've spent almost 40hrs on is almost complete, but I have
I have gotten almost a complete API to work, with creating and deleting documents
I have a site using CodeIgniter that is almost complete now. My problem is
I have written a simple game and am looking to integrate GameCenter Achievements with
I have to implement game of life, it is almost complete, the last thing
I have got the following problem with F# code recently: almost the complete code
I have almost the worst spec in the world. An application that exists and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.