CherryPy Project Download

Storm is the ORM from Canonical (makers of Ubuntu.) Here is the simple implementation I have that utilizes CP 3.1 (Currently Beta) and Storms current trunk release (.11 i believe it is).

For my connection setup, here is the code.

def connect_db(thread_index):

database = create_database(cherrypy.config.get('storm.default.url')) = Store(database) cherrypy.engine.subscribe('start_thread', connect_db) In your config file you will want:

storm.default.url = "postgres://postgres:pass@server:5432/database" Here is a sample method that uses genshi, storm etc:

@cherrypy.expose @template.output('index.html') def index(self, site_id=1):

site =, Site.site_id == 1).one() return template.render(site=site)

Instead of doing a commit on every query in every action you can allow the request handler to do the commit for you. This is very similar to the Dejavu example shown in the tools section as well. This basically attempts to do a commit and if it doesn't commit it does a rollback and spits out an error.

def do_commit():
		cherrypy.log(format_exc(), "STORM")

def try_commit():
		cherrypy.request.hooks.attach('on_end_request', do_commit)
		if isinstance(cherrypy.response.body, types.GeneratorType):
		do_commit() = cherrypy.Tool('on_end_resource', try_commit)

Simply create the tool and then in your config you need to have

tools.storm.on = True

Hosted by WebFaction

Log in as guest/cherrypy to create/edit wiki pages