Hyperminimal WSGI framework
Switch branches/tags
hudson-dream-84 hudson-dream-83 hudson-dream-82 hudson-dream-81 hudson-dream-81-SUCCESS hudson-dream-80 hudson-dream-80-SUCCESS hudson-dream-79 hudson-dream-79-SUCCESS hudson-dream-78 hudson-dream-78-SUCCESS hudson-dream-77 hudson-dream-77-SUCCESS hudson-dream-76 hudson-dream-76-SUCCESS hudson-dream-75 hudson-dream-75-SUCCESS hudson-dream-74 hudson-dream-74-SUCCESS hudson-dream-73 hudson-dream-73-SUCCESS hudson-dream-72 hudson-dream-72-SUCCESS hudson-dream-71 hudson-dream-71-SUCCESS hudson-dream-70 hudson-dream-70-SUCCESS hudson-dream-69 hudson-dream-68 hudson-dream-67 hudson-dream-66 hudson-dream-65 hudson-dream-65-SUCCESS hudson-dream-64 hudson-dream-63 hudson-dream-63-SUCCESS hudson-dream-34 hudson-dream-33 hudson-dream-33-SUCCESS hudson-dream-32 hudson-dream-32-SUCCESS hudson-dream-31 hudson-dream-31-SUCCESS hudson-dream-30 hudson-dream-30-SUCCESS hudson-dream-29 hudson-dream-29-SUCCESS hudson-dream-28 hudson-dream-28-SUCCESS hudson-dream-27 hudson-dream-27-SUCCESS hudson-dream-26 hudson-dream-26-SUCCESS hudson-dream-25 hudson-dream-25-SUCCESS hudson-dream-24 hudson-dream-24-SUCCESS hudson-dream-23 hudson-dream-23-SUCCESS hudson-dream-22 hudson-dream-22-SUCCESS hudson-dream-21 hudson-dream-21-SUCCESS hudson-dream-20 hudson-dream-20-SUCCESS hudson-dream-19 hudson-dream-19-SUCCESS hudson-dream-18 hudson-dream-18-SUCCESS hudson-dream-17 hudson-dream-17-SUCCESS hudson-dream-16 hudson-dream-16-SUCCESS hudson-dream-15 hudson-dream-15-SUCCESS hudson-dream-14 hudson-dream-13 hudson-dream-13-SUCCESS hudson-dream-12 hudson-dream-12-SUCCESS hudson-dream-11 hudson-dream-11-SUCCESS hudson-dream-10 hudson-dream-10-SUCCESS hudson-dream-9 hudson-dream-9-SUCCESS hudson-dream-8 hudson-dream-8-SUCCESS hudson-dream-7 hudson-dream-7-SUCCESS hudson-dream-6 hudson-dream-6-SUCCESS hudson-dream-5 hudson-dream-5-SUCCESS hudson-dream-4 hudson-dream-4-SUCCESS hudson-dream-3 debian/1.0.84 debian/1.0.82 debian/1.0.81
Nothing to show
Latest commit 1bfc602 Dec 16, 2011 Jenkins slave user Prepared changelog for build 84
Failed to load latest commit information.
.gitignore Add coverage commands to Makefile. Sep 2, 2011
LICENSE Add license. Jan 4, 2011
README.org Fix shell examples. Jan 4, 2011
setup.py Prepared changelog for build 84 Dec 16, 2011



Dream is a hyper-minimal framework for creating WSGI apps, which leverages decoroute and WebOb to dispach and abstract requests. It’s particularly good for API type applications, as this is what it was originally written to support.


Abstracted away from WSGI

You only have to deal with WebOb’s Request objects, and your functions return Response objects.

Nothing you don’t need

Very lightweight. No ORM. No admin page. Just URL routing and request/response objects.

Per-method endpoints

Decoroute has been extended to allow invoking different functions for the same URL based on the request method. This avoids ugly conditional code in your endpoint functions.

Conveniently namespaced

Common classes from WebOb & Decoroute are imported into the dream namespace — no need for anything other than import dream.

JSONResponse class

Since returning JSON is a common thing to do with Dream, there’s a Response subclass which will serialize it out for you. If you want a response intended for human consumption, there is also the clunkily-named HumanReadableJSONResponse.

Exception handling

Unhanded exceptions are caught and returned as 500 responses, with the exception reason in a JSON payload.

Endpoint introspection

Easily see the endpoints you’ve defined:

Crash course

Drop this into in my_app.py:

import dream

App = dream.App()

def hello_json(request):
    return dream.JSONResponse(body={'greeting': 'Hello, world!'})

def hello_text(request):
    return dream.Response(body='Hello, world!',
                          headers={'Content-Type': 'text/plain'})

def hello_user(request, person):
    return dream.Response(body='Nice to meet you, %s' % person,
                          headers={'Content-Type': 'text/plain'})

Run it:

$ gunicorn my_app:App &
$ curl -i http://localhost:8080/greeting.json
$ curl -i http://localhost:8080/greeting.txt

Endpoint introspection

If you’d like to add an endpoint which returns known endpoints, add the following line:

dream.endpoints(App, '/endpoints.json')