Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

CherryPy tool for Psycopg 2 database connections

Project Description


In the CherryPy application, install the psycopg2 tool:

import cherrypy_psycopg2

Configure the tool in the usual CherryPy way:

tools.psycopg2.minconn = 1
tools.psycopg2.maxconn = 5
tools.psycopg2.dsn = "dbname=production"

When the tool is turned on, a Psycopg2 connection instance is made available to handlers at cherrypy.thread_data.psycopg2_connection:
def query(self):
    connection = cherrypy.thread_data.psycopg2_connection
    cursor = connection.cursor()
    cursor.execute("SELECT 1")


The transaction is committed once the handler has completed, provided the handler:

  • returned successfully,
  • or raised one of:
    • cherrypy.HTTPRedirect,
    • cherrypy.InternalRedirect,
    • cherrypy.NotFound.

Any other exception will cause a transaction rollback.


Development aims to be behavior-driven, assisted by the behave tool.

Release History

Release History

This version
History Node


Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting