Skip to main content

WSGI Middleware for embedding a rich profiler in web pages.

Project description

First install WSGIProfile. You may also need to install the python-profiler package if you are on Ubuntu.

easy_install WSGIProfile
sudo apt-get install python-profiler

Next lets create a very simple WSGI application with one slow function:

import time

def app(environ, start_response):
    time.sleep(2)
    start_response('200 OK', [('Content-Type', 'text/html')])
    return ['Hello World!']

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    server = make_server('127.0.0.1', 8080, app)
    server.serve_forever()

Point your browser at http://localhost:8080 and you should see “Hello World!”.

Adding profiling information to this application is as simple as wrapping the application function in some profiling middleware:

app = ProfileMiddleware(app)

Our example now looks like this:

import time

def app(environ, start_response):
    time.sleep(2)
    start_response('200 OK', [('Content-Type', 'text/html')])
    return ['Hello World!']

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    from wsgiprofile import ProfileMiddleware
    app = ProfileMiddleware(app)
    server = make_server('127.0.0.1', 8080, app)
    server.serve_forever()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for WSGIProfile, version 0.1dev
Filename, size File type Python version Upload date Hashes
Filename, size WSGIProfile-0.1dev-py2.5.egg (15.0 kB) File type Egg Python version 2.5 Upload date Hashes View
Filename, size WSGIProfile-0.1dev.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page