Skip to main content

CherryPy tool to manage Psycopg 2 database connections

Project description

CherryPy-Psycopg2

CherryPy-Psycopg2 is a simple CherryPy Tool to manage a (thread-safe) pool of database connections and make them available to handlers.

Import cherrypy_psycopg2 to make the tool available in CherryPy's default toolbox.

The following configuration settings are understood:

  • tools.psycopg2.minconn - passed to the psycopg2 pool constructor
  • tools.psycopg2.maxconn - passed to the psycopg2 pool constructor
  • tools.psycopg2.dsn - passed to the psycopg2 pool constructor
  • tools.psycopg2.cursor_factory - passed to the psycopg2 connection's cursor() method

When the tool is enabled on a handler, it will collect a database connection from the pool, expose a cursor as cherrypy.request.psycopg2_cursor, execute the handler and then commit the transaction (if the handler was successful or raised one of the cherrypy_psycopg2.COMMITTABLE_HANDLER_EXCEPTIONS), or rollback the transaction if the handler raised any other exception.

For example:

class Root:
    @cherrypy.expose
    @cherrypy.tools.psycopg2()
    def index(self):
        cursor = cherrypy.request.psycopg2_cursor
        cursor.execute("SELECT now()")

        return cursor.fetchone()[0]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cherrypy-psycopg2-2.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

cherrypy_psycopg2-2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file cherrypy-psycopg2-2.0.tar.gz.

File metadata

  • Download URL: cherrypy-psycopg2-2.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.9

File hashes

Hashes for cherrypy-psycopg2-2.0.tar.gz
Algorithm Hash digest
SHA256 5d96a6702094a0d0544607e922c1f85461ec414fe71b8fe52b4b354e89d785b9
MD5 e1a6a797d30764cab3fd576dd6890ed5
BLAKE2b-256 f733bce54a7d0c9792c1e5573aa26d0748c1c409753eb77e26db974ab4c83c27

See more details on using hashes here.

File details

Details for the file cherrypy_psycopg2-2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cherrypy_psycopg2-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3b1738286ca20001697586c4c782f8578eb2e40a776aae179a3e5f24d6f94ee
MD5 f2bb17bccc894c69faa5f839af51253e
BLAKE2b-256 eff6d38a0127511581db05150c00e9217290856f72575379b49b0d7229bd7dec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page