skillfed

psycopg2-pool

Proper pooling of psycopg2 connections

psycopg2-pool v1.2 311.4K downloads/30d#7,735 on PyPI4
Copyleft license LGPL3 DORMANT released

What it is and what it does

psycopg2-pool wraps psycopg2 to provide thread-safe connection pooling for PostgreSQL. Instead of opening and closing a new database connection for each request—an expensive operation—the pool maintains a set of open connections that applications can borrow and return, reducing latency and resource consumption in concurrent workloads.

The package exports a ThreadSafeConnectionPool class that manages a minimum and maximum number of connections, handing them out on demand and recycling them back into the pool. It is designed for multi-threaded Python applications that make frequent database queries and need to amortize connection setup costs. The library depends only on psycopg2-binary and installs as a pure Python wheel.

Use it for:

  • Web applications serving concurrent requests that each need a database connection.
  • Multi-threaded batch processing jobs that query PostgreSQL repeatedly and need to avoid connection exhaustion.
  • Long-running services that spawn worker threads and need a shared, thread-safe pool of database connections.
  • Testing frameworks that run parallel test suites against a shared PostgreSQL database.
  • Applications requiring reduced connection setup latency in high-concurrency scenarios.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Manages a pool of reusable PostgreSQL connections via psycopg2, reducing connection overhead in multi-threaded applications.

Yes, if you are building a multi-threaded Python application that queries PostgreSQL frequently. The package is simple, has low install friction, carries no known vulnerabilities, and solves a real problem. The dormant maintenance status is a minor concern—monitor for breaking changes in psycopg2 or PostgreSQL—but the code is stable. Be aware of the LGPL3 copyleft license if your application is proprietary.

Install

psycopg2-pool on PyPI

pip

pip install psycopg2-pool

uv

uv add psycopg2-pool

poetry

poetry add psycopg2-pool

Installing psycopg2-pool

Before you install

Low friction: pure Python wheel with a single runtime dependency on psycopg2-binary. Maintenance is dormant—last commit was 2024-05-10—but the package is marked Production/Stable.

License in practice

Licensed under LGPL3 (copyleft). Any application that links this library must make its own source code available under a compatible license or comply with LGPL3's linking exceptions.

Quickstart

pip install psycopg2-pool

from psycopg2_pool import ThreadSafeConnectionPool

pool = ThreadSafeConnectionPool(1, 10, "dbname=test user=postgres")
conn = pool.getconn()
# use conn
pool.putconn(conn)

Requires psycopg2-binary installed; application must manage connection lifecycle (getconn/putconn calls).

Verify before relying

  • Whether the dormant maintenance status (942 days since latest release) poses a risk for future PostgreSQL or psycopg2 compatibility.
  • Performance characteristics and overhead compared to other pooling solutions.
  • Specific threading model and concurrency limits of ThreadSafeConnectionPool.

Package facts

License LGPL3 (copyleft)
Python support supports the current Python release (>=3.3)
Install friction low — pure-Python wheel
Runtime dependencies 1 — psycopg2-binary
Maintenance dormant — 942 days since the last release
Last repo commit
First released
Downloads 311,370/month — #7,735 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: psycopg2_pool-1.2-py2.py3-none-any.whl

Keywords: postgres, psycopg2

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python

Tags

psycopg2 connection poolingpostgresql connection poolthread-safe database connectionsreuse postgres connectionsconnection pool managementpsycopg2 thread pooldatabase connection caching
connection-poolingpostgresqlconcurrency

More Database packages