python-aiomysql
Installation
SKILL.md
aiomysql — Async MySQL for Python
aiomysql provides asyncio-native access to MySQL databases. It wraps PyMySQL with async/await support and exposes Connection, Cursor, and Pool primitives that mirror the synchronous DBAPI interface.
Requirements: Python 3.9+, PyMySQL. Install with:
pip install aiomysql
# Optional SQLAlchemy expression layer:
pip install aiomysql sqlalchemy
Core Principles
- Always use a connection pool (
create_pool) in production — never bareconnect()for long-lived services. - Always use async context managers (
async with) to guarantee connection and cursor release. - Never format SQL strings manually. Always pass parameters as the second argument to
execute(). - Commit explicitly;
autocommitdefaults toFalse. - Close the pool cleanly on shutdown:
pool.close()thenawait pool.wait_closed().