aiomysql
MySQL driver for asyncio.
What it is and what it does
aiomysql is an async wrapper around PyMySQL that lets you execute MySQL queries without blocking your asyncio event loop. It reuses PyMySQL's connection logic and SQL parsing but replaces all blocking I/O calls with async equivalents, so you can use `await` and `async with` to manage connections, cursors, and queries. The API mirrors PyMySQL closely, making it familiar if you've used that library, and it includes optional SQLAlchemy integration ported from aiopg for ORM-style queries.
You create a connection pool with `create_pool()`, acquire connections from it, and execute queries through cursors—all with `await`. It supports both raw SQL and SQLAlchemy table operations, and works across Python 3.9 through 3.13. The package is actively maintained, has no known vulnerabilities, and carries an MIT license.
Use it for:
- Build async web services (FastAPI, aiohttp) that query MySQL without blocking the event loop.
- Write concurrent batch jobs that fetch or insert data into MySQL from multiple coroutines.
- Integrate MySQL with SQLAlchemy in async frameworks using the `aiomysql.sa` module.
- Handle high-concurrency scenarios where traditional blocking drivers would exhaust thread pools.
- Migrate from aiopg to MySQL while preserving async/await patterns and similar API structure.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
aiomysql provides async/await access to MySQL databases by wrapping PyMySQL with asyncio support, letting you query MySQL non-blockingly from async Python code.
Yes. aiomysql is a straightforward, low-friction async MySQL driver with active maintenance, no security issues, permissive licensing, and broad Python version support. Install it if you need non-blocking MySQL access in an asyncio application; the single dependency (PyMySQL) and pure-Python wheel keep setup simple.
Install
aiomysql on PyPI
pip
pip install aiomysqluv
uv add aiomysqlpoetry
poetry add aiomysqlInstalling aiomysql
Before you install
Low friction: pure Python wheel with a single runtime dependency (PyMySQL). Actively maintained with recent commits and a stable repository; marked Alpha but in use across a broad Python version range (3.9–3.13).
License in practice
MIT license is permissive; you may use, modify, and distribute aiomysql with minimal restrictions, making it suitable for both open-source and commercial projects.
Quickstart
import asyncio
import aiomysql
async def query():
async with aiomysql.create_pool(host='127.0.0.1', user='root', db='mysql') as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 42;")
result = await cur.fetchone()
print(result)
asyncio.run(query())
Requires a running MySQL server and valid connection credentials; Python 3.9 or later.
Verify before relying
- Whether the Alpha status (Development Status :: 3) reflects active development or stable-but-unversioned API.
- Performance characteristics compared to other async MySQL drivers in production workloads.
- Compatibility with MariaDB versions beyond basic keyword mention.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — PyMySQL |
| Maintenance | actively maintained — 296 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 16,758,493/month — #1,140 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aiomysql-0.3.2-py3-none-any.whl
Keywords: mysql, mariadb, asyncio, aiomysql
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
aioodbcaioodbc provides async/await access to ODBC…
permissive · top 5,000 on PyPI
aiopgaiopg provides asyncio-based access to…
permissive · top 15,000 on PyPI
databasesProvides async database access for PostgreSQL,…
permissive · top 5,000 on PyPI
hopsworks-aiomysqlAsync MySQL database driver for Python asyncio…
permissive · top 15,000 on PyPI
asyncmyasyncmy is an asyncio-native MySQL/MariaDB…
permissive · top 5,000 on PyPI
asyncmy2asyncmy2 is a fast asyncio-based MySQL/MariaDB…
permissive · top 15,000 on PyPI
anysqliteAnysqlite wraps SQLite with an async/await…
unclear · top 5,000 on PyPI
aiosqlLoad SQL queries from files and call them as…
permissive · top 15,000 on PyPI
PyMySQLPyMySQL is a pure-Python MySQL and MariaDB…
permissive · top 1,000 on PyPI
myclimycli is a command-line client for MySQL and…
permissive · top 15,000 on PyPI