Monday, 8 March 2010

Announcing twod.wsgi: Better WSGI support for Django

We are very pleased to announce the first alpha release of twod.wsgi, a library to make WSGI a first-class citizen in Django applications.

twod.wsgi allows Django developers to take advantage of the huge array of existing WSGI software, to integrate 3rd party components which suit your needs or just to improve things which are not within the scope of a Web application framework.

It ships with a PasteDeploy application factory (which gives the enterprise some of what it needs) and full-featured request objects extended by WebOb. It also gives you the ability to serve WSGI applications inside Django, so you can filter the requests they get and/or the responses they return (e.g., to implement Single Sign-On mechanisms). And there's more!

For example, if you wanted to integrate your authentication mechanisms with your Trac application, you could do it in 11 lines of code:

from django.shortcuts import redirect
from django.conf import settings

from twod.wsgi import call_wsgi_app
from trac.web.main import dispatch_request as trac_app

def make_trac(request, path_info):

    if path_info.startswith("/login"):
        return redirect(request.script_name + "/login")
    elif path_info.startswith("/logout"):
        return redirect(request.script_name + "/logout")

    request.environ['trac.env_path'] = settings.TRAC_PATH
    return call_wsgi_app(trac_app, request, path_info)

Don't be fooled by the "first alpha release": It's rock-solid. We've been using it for months in our Web site and it's never ever failed. It just means the API might change in a backwards incompatible way by the final release -- Which is very unlikely given how simple it is.

It's also comprehensively documented and tested. For all these reasons, we believe it's safe to say it's production ready.

Be warned, WSGI is very addictive! If you like it, please support it.

1 comments:

Attila Oláh said...

Hello Gustavo,

Great to see that once again you've come up with a brilliant solution! I've been looking for something like this for quite some tome now, until I've found it. Now I use it on App Engine to make other WSGI middlewares play nice with Django. I figured I just need to call twod.wsgi.DjangoApplication() and pass it to google.appengine.ext.webapp.util.run_wsgi_app(), and now all my views get the nice TwodWSGIRequest objects.

Again, thanks for releasing this great piece of software!

Post a Comment