$ show aio-libs/aiomysql
aiomysql is a pure-Python MySQL/MariaDB client library for asyncio. It is effectively a port of PyMySQL's blocking driver with async I/O, plus an optional SQLAlchemy integration layer ported from aiopg. The primary programmatic entry points are `aiomysql.connect()` and `aiomysql.create_pool()`, which produce `Connection` and `Pool` objects used through `connection.cursor()`, `cursor.execute()`, and async context managers. A secondary entry point is `aiomysql.sa.create_engine()`, which wraps async pools with a SQLAlchemy engine/dialect facade for expression-based queries. The library implements MySQL protocol packet handling, authentication plugins, TLS, `LOAD DATA LOCAL INFILE`, server-side cursors, and result-set decoding. It has no web endpoints, CLI, or data pipelines; it is a dependency library, not an end-user application.
The LLM identified 3 files worth highlighting for reuse:
Defines a family of small async context-manager classes (`_ContextManager`, `_ConnectionContextManager`, `_PoolAcquireContextManager`, etc.) that transform coroutine factories into `async with`-friendly objects with cleanup semantics. These are nearly dependency-free and demonstrate a reusable pattern for wrapping async resource acquisition and release in a generic way.
Implements cursor variants through mixins (`DictCursor`, `DeserializationCursor`) and a non-obvious `executemany` optimization that collapses repeated `INSERT`/`REPLACE` statements into a single multi-row VALUES statement using a MySQL-specific regex (RE_INSERT_VALUES). The mixin composition approach is a clean demonstration of building custom cursor behavior without duplicating protocol logic.
Provides an async connection pool built on `asyncio.Condition`, with tracked free/used connections, automatic pool filling, recycling of stale connections, and detection of server-closed connections via a custom EOF-aware stream reader. Although coupled to aiomysql's connection objects, its design and invariants form a solid reference pattern for implementing robust async resource pools with backpressure and cleanup.