Registry / database / pymysql-pool

pymysql-pool

JSON →
library0.5.0pypypi✓ verified 87d ago

PyMySQL Pool is a high-performance MySQL connection pool built on top of PyMySQL, supporting connection reuse, configurable pool limits, connection lifetime management, and automatic rollback/re-autocommit on return. Version 0.5.0 (stable) supports Python >=3.7, last release 2022-06.

pip install pymysql-pool
INSTALL
IMPORT
SIG · PYMYSQL-POOL
P
pymysql-pool
databasepythonv0.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ConnectionPool
✓ from pymysqlpool import ConnectionPool
✗ from pymysqlpool.pool import ConnectionPool
Top-level import is the canonical path.
PooledConnection
✓ from pymysqlpool import PooledConnection

Create a pool, borrow a connection via get_conn(), use it, then release it back.

from pymysqlpool import ConnectionPool pool = ConnectionPool( host='localhost', user='root', password=os.environ.get('MYSQL_PWD', ''), database='test', maxsize=10, pre_create_num=2, pool_name='mypool' ) conn = pool.get_conn() cursor = conn.cursor() cursor.execute('SELECT 1') result = cursor.fetchone() cursor.close() pool.release(conn) print(result)
Debug
Known issues
breakingIn v0.3.7, the parameter 'max_size' was renamed to 'maxsize' in ConnectionPool.__init__. Older code using max_size will raise TypeError.
fix
Use maxsize=... instead of max_size=...
affects: >=0.3.7
breakingIn v0.4.3, pool.size was renamed to pool.available_num and pool.connection_num to pool.total_num.
fix
Use pool.available_num and pool.total_num instead.
affects: >=0.4.3
gotchaConnections must be returned to the pool via pool.release(conn). Forgetting to release may exhaust the pool and cause hangs.
fix
Always call pool.release(conn) in a finally block or use context manager (pool.connection()) if available.
affects: all
Errors
Common errors & fixes
AttributeError: module 'pymysqlpool' has no attribute 'ConnectionPool'
Outdated version or incorrect import (e.g. from pymysqlpool.pool import ConnectionPool). The top-level import is the correct one only from v0.4.x onward.
fix
Use 'from pymysqlpool import ConnectionPool' after pip install --upgrade pymysql-pool.
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
The server-side wait_timeout closes idle connections. pymysql-pool's con_lifetime parameter was introduced to re-create connections automatically.
fix
Set con_lifetime (in seconds) to a value less than MySQL wait_timeout, e.g. pool = ConnectionPool(..., con_lifetime=3600).
TypeError: __init__() got an unexpected keyword argument 'max_size'
Parameter renamed from max_size to maxsize in v0.3.7.
fix
Use maxsize=... instead.
Upgrade
Version history
0.5.0latest on PyPI · released May 21, 2025
Audit
Dependencies
PyMySQLrequiredpymysql-pool wraps PyMySQL connections
Agent activity
5 hits · last 30 days
node
5
Resources
pymysql-pool — pip install pymysql-pool · libregistry