Werkzeug

Serving WSGI Applications

Navigation

There are many ways to serve a WSGI application. While you're developing it you usually don't want a full blown webserver like Apache but a simple standalone one. With Python 2.5 onwards there is the wsgiref server in the standard library. If you're using older versions of Python you can download the package from the cheeseshop.

However there are some caveats. Sourcecode won't reload itself when changed and each time you kill the server using ^C you get an KeyboardInterrupt error. While the latter is easy to solve the first one can be a pain in the ass in some situations.

Because of that Werkzeug ships a small wrapper over wsgiref that spawns the WSGI application in a subprocess and automatically reloads the application if a module was changed.

The easiest way is creating a small start-myproject.py that runs the application:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from myproject import make_app
from werkzeug import run_simple

app = make_app(...)
run_simple('localhost', 8080, app, use_reloader=True)

You can also pass it a extra_files keyword argument with a list of additional files (like configuration files) you want to observe.