Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: f20c1fefdf
Fetching contributors…

Cannot retrieve contributors at this time

105 lines (67 sloc) 3.063 kB


This is a collection of addons and accompanying unit tests for the excellent Tornado web server

These addons are licensed the same as Tornado under the Apache Licence, Version 2.0 (


Just place this directory in your python path or run the following:

sudo python install


Every addon will have a set of accompanying unit tests. We prefer to run them via Nose.

cd tornado_addons/


The best source of information is the comments in or They're fairly well commented and give a better understanding of the libs.


Here's a simple example.

import tornado.web
from tornado_addons.route import route

class SomeHandler(tornado.web.RequestHandler):

t = tornado.web.Application(route.get_routes(), {'some app': 'settings'}

Async yields

Here's an example with normal callbacks.

from tornado.httpclient import AsyncHTTPClient

class SomeHandler(tornado.web.RequestHandler):
    def get(self):
        self.somedata = 'xxx'
        AsyncHTTPClient.fetch( 'http://over/there',
            callback=self.my_async_http_cb )

    def my_async_http_cb(self, fetch_data):
        # do stuff with fetchdata here

Or, you can wrap your methods with async_yield...

from tornado_addons.async_yield import async_yield, AsyncYieldMixin

class SomeHandler(tornado.web.RequestHandler, AsyncYieldMixin):
    def get(self):
        somedata = 'xxx'
        fetchdata = yield AsyncHTTPClient.fetch( 'http://over/there',
                              callback=self.mycb )
        # do stuff with fetchdata here
        self.write(fetchdata.body if not fetchdata.error else '')

The @async_yield wrapper doesn't work for every method with callbacks but it does cleanup your RequestHandlers quite nicely and really streamlines workflow.

You begin to see the real power of this when you start to have handlers that make multiple async calls.


Cushion is a bit of an extraction layer around trombi, an asynchronous CouchDB driver for Tornado.

It provides a mixin for RequestHandler that simplifies database access, especially when used in conjunction with async_yield.

from tornado.web import RequestHandler
from tornado_addons.cushion import CushionDBMixin
from tornado_addons.async_yield import async_yield, AsyncYieldMixin

class SomeHandler(RequestHandler, CushionDBMixin, AsyncYieldMixin):

    def prepare(self):
        yield self.db_setup('someDB', uri_to_couchdb, self.yield_cb)

    def get(self):
        x = yield self.db_one('some_key')
        # ... do stuff wth your data in x now
Jump to Line
Something went wrong with that request. Please try again.