psycopg_pool – Connection pool implementations¶
The package contains two connection pool implementations. A connection pool creates and maintains a limited amount of PostgreSQL connections and allows a larger number of users to use them. See Connection pools for more details and usage pattern.
This module implement two connection pools: ConnectionPool is a
synchronous connection pool yielding Connection objects and can be
used by multithread applications. AsyncConnectionPool has a similar
interface, but with asyncio functions replacing blocking functions, and
yields AsyncConnection instances.
The intended use (but not mandatory) is to create a single connection pool, as
a global object exposed by a module in your application, and use the same
instance from the rest of the code (especially the
connection() method.
Note
The psycopg_pool package is distributed separately from the main
psycopg package: use pip install psycopg[pool] or pip install
psycopg_pool to make it available. See Installing the connection pool.
The ConnectionPool class¶
Pool exceptions¶
The AsyncConnectionPool class¶
AsyncConnectionPool has a very similar interface to the ConnectionPool
class but its blocking method are implemented as async coroutines. It
returns AsyncConnection instances, or its subclasses if specified
so in the connection_class parameter.
Only the function with different signature from ConnectionPool are
listed here.