Skip to main content

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]

Metadata

Release files for cherrypy-psycopg2 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cherrypy-psycopg2 2.0
File Size Uploaded
cherrypy-psycopg2-2.0.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cherrypy-psycopg2 2.0
File Interpreter ABI Platform
cherrypy_psycopg2-2.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / cherrypy-psycopg2-2.0.tar.gz

Download URL cherrypy-psycopg2-2.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5d96a6702094a0d0544607e922c1f85461ec414fe71b8fe52b4b354e89d785b9
BLAKE2b-256 checksum
How to use checksums
f733bce54a7d0c9792c1e5573aa26d0748c1c409753eb77e26db974ab4c83c27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.9

Release files / cherrypy_psycopg2-2.0-py3-none-any.whl

Download URL cherrypy_psycopg2-2.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3b1738286ca20001697586c4c782f8578eb2e40a776aae179a3e5f24d6f94ee
BLAKE2b-256 checksum
How to use checksums
eff6d38a0127511581db05150c00e9217290856f72575379b49b0d7229bd7dec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.9

Release history Release notifications | RSS feed

This release

2.0 This release

2 release files

1.2

2 release files

1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page