aiomysql is a Python library that accesses MySQL databases from asyncio code, reusing PyMySQL APIs with async I/O and optional SQLAlchemy integration.
Overview
aiomysql provides a driver for talking to MySQL from the asyncio framework. It builds on PyMySQL internals with async calls added at the I/O boundary, and aims to mirror the aiopg style so methods are awaited instead of called synchronously while properties behave the same as in PyMySQL.
The library exposes asyncio DBAPI-like Connection, Cursor, and Pool objects for direct SQL use. An optional aiomysql.sa module ports SQLAlchemy functional SQL support from aiopg, including engine creation, inserts, selects, and async iteration over rows.
Installation is via pip and requires PyMySQL; the SQLAlchemy layer needs sqlalchemy installed separately. Documentation covers basic connection and pool examples, requirements of Python 3.9 or newer, and parity with PyMySQL calling conventions for application code.
The project is maintained on GitHub under the aio-libs ecosystem, uses continuous integration and coverage reporting, and is MIT licensed like PyMySQL.
Key features
- Async MySQL connections and pools
- PyMySQL-compatible method surface
- Asyncio DBAPI-style cursor API
- Optional SQLAlchemy engine integration
- MIT license aligned with PyMySQL
- Documented install via pip
- GitHub Actions CI and coverage
- Coroutine-based I/O on PyMySQL core
Use cases
- Async web apps querying MySQL
- High-concurrency database access in asyncio
- SQLAlchemy async workloads on MySQL
- Migrating synchronous PyMySQL call sites
- Connection pooling in asyncio services