Connection Pool
raw JSON → 0.0.3 verified Mon Apr 27 auth: no python maintenance
A minimal thread-safe connection pool for Python, providing a generic pool for any reusable connections (e.g., database sockets, HTTP clients). Version 0.0.3 is the latest release as of early 2025; the project appears to be in maintenance mode with no recent updates.
pip install connection-pool Common errors
error ModuleNotFoundError: No module named 'connection_pool' ↓
cause Using wrong import path (hyphen instead of underscore). The package slug is 'connection-pool' but import uses underscore.
fix
Install with
pip install connection-pool and import as from connection_pool import ConnectionPool. error connection_pool.ConnectionPool object has no attribute 'get_connection' ↓
cause Attempting to use a method that does not exist. The correct API is `pool.acquire()`
fix
Use
pool.acquire() to obtain a connection. Warnings
gotcha The library does not support connection validation or health checks. If a connection is broken after acquisition, the pool does not detect it. ↓
fix Implement your own validation before returning connections to the pool.
gotcha The library uses a simple list-based queue which may not be suitable for high-concurrency scenarios. Performance may degrade under heavy load. ↓
fix Consider using more robust pools like SQLAlchemy's or redis-py's connection pool for production.
gotcha The `acquire()` method will block indefinitely if the pool is exhausted and no timeout is set. This can cause deadlocks. ↓
fix Always specify a timeout when acquiring connections: `pool.acquire(timeout=5)`.
Imports
- Pool
from connection_pool import ConnectionPool
Quickstart
from connection_pool import ConnectionPool
# Create a pool with a factory function for connections
pool = ConnectionPool(
max_size=5,
create=lambda: {'conn': 'example'},
close=lambda conn: None
)
# Acquire a connection
with pool.acquire() as conn:
# Use the connection
print(conn)
pass
# Connections are returned automatically