Python Paste


CherryPaste is a project to make CherryPy and TurboGears apps compatible with Paste.

This is done by making cherrypy.root and cherrypy.config.configs thread-local, and swapping in the current config and root object for the request.

As a result, this isn't compatible with all CherryPy projects, but should (may) be compatible with some. Special attention is given to TurboGears, particularly because TG apps are more constrained than just CherryPy apps in general.

Configuration is simple:

use = egg:CherryPaste
root_object = mypackage.root:Root()
other_config = a
other_other_config = b

This will use an instance of the Root object from the mypackage.root module as the root object of the CherryPy app (multiple root objects are fine, this is just the root for this application). Note, if you want an instance to be the root, use mypackage.root:Root() (basically whatever is after the : is evaluated in the scope of the module).

There are also entry points (which are just small wrappers around the entry point used above) for TurboGears and CatWalk:

use = egg:CherryPaste#turbogears
egg = MyPackage

use = egg:CherryPaste#catwalk
model = mypackage.model
# optional:
database = mysql://...


An application should not try to patch cherrypy.root on its own. It also sets up a configuration like {'other_config': 'a', 'other_other_config': 'b'}. (I suspect this isn't sufficiently complete configuration, but it's a starting point.)

Configuration should not be done on import if the application is to be compatible with Paste. Configuration may be swapped in, and the same application used multiple times, so configuration values should be read only when they are actually used. If you do not do this, you may get some funny behavior if you run multiple CherryPy apps in the same process (though with just one app it should be equivalent to normal CherryPy operation, especially if you use lazy_fake = true).

If you add a section like this to your configuration file:

use = egg:Paste#http
host =
port = 8080

Then you can do:

paster serve config_file.ini

And you'll have a server with your app. Other Paste techniques are also possible, of course.