{"id":28092,"library":"pymysql-pool","title":"PyMySQL Pool","description":"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.","status":"active","version":"0.5.0","language":"python","source_language":"en","source_url":"https://github.com/jkklee/pymysql-pool","tags":["mysql","connection-pool","pymysql","database","pool"],"install":[{"cmd":"pip install pymysql-pool","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"pymysql-pool wraps PyMySQL connections","package":"PyMySQL","optional":false}],"imports":[{"note":"Top-level import is the canonical path.","wrong":"from pymysqlpool.pool import ConnectionPool","symbol":"ConnectionPool","correct":"from pymysqlpool import ConnectionPool"},{"note":"","wrong":"","symbol":"PooledConnection","correct":"from pymysqlpool import PooledConnection"}],"quickstart":{"code":"from pymysqlpool import ConnectionPool\n\npool = ConnectionPool(\n    host='localhost',\n    user='root',\n    password=os.environ.get('MYSQL_PWD', ''),\n    database='test',\n    maxsize=10,\n    pre_create_num=2,\n    pool_name='mypool'\n)\nconn = pool.get_conn()\ncursor = conn.cursor()\ncursor.execute('SELECT 1')\nresult = cursor.fetchone()\ncursor.close()\npool.release(conn)\nprint(result)","lang":"python","description":"Create a pool, borrow a connection via get_conn(), use it, then release it back."},"warnings":[{"fix":"Use maxsize=... instead of max_size=...","message":"In v0.3.7, the parameter 'max_size' was renamed to 'maxsize' in ConnectionPool.__init__. Older code using max_size will raise TypeError.","severity":"breaking","affected_versions":">=0.3.7"},{"fix":"Use pool.available_num and pool.total_num instead.","message":"In v0.4.3, pool.size was renamed to pool.available_num and pool.connection_num to pool.total_num.","severity":"breaking","affected_versions":">=0.4.3"},{"fix":"Always call pool.release(conn) in a finally block or use context manager (pool.connection()) if available.","message":"Connections must be returned to the pool via pool.release(conn). Forgetting to release may exhaust the pool and cause hangs.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use 'from pymysqlpool import ConnectionPool' after pip install --upgrade pymysql-pool.","cause":"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.","error":"AttributeError: module 'pymysqlpool' has no attribute 'ConnectionPool'"},{"fix":"Set con_lifetime (in seconds) to a value less than MySQL wait_timeout, e.g. pool = ConnectionPool(..., con_lifetime=3600).","cause":"The server-side wait_timeout closes idle connections. pymysql-pool's con_lifetime parameter was introduced to re-create connections automatically.","error":"pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')"},{"fix":"Use maxsize=... instead.","cause":"Parameter renamed from max_size to maxsize in v0.3.7.","error":"TypeError: __init__() got an unexpected keyword argument 'max_size'","affected_versions":">=0.3.7"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}