aiomysql is a “driver” for accessing a MySQL database from the asyncio (PEP-3156/tulip) framework. It depends on and reuses most parts of PyMySQL . aiomysql tries to be like awesome aiopg library and preserve same api, look and feel.
Internally aiomysql is copy of PyMySQL, underlying io calls switched to async, basically yield from and asyncio.coroutine added in proper places)). sqlalchemy support ported from aiopg.
Documentation
Basic Example
aiomysql based on PyMySQL , and provides same api, you just need to use await conn.f() or yield from conn.f() instead of calling conn.f() for every method.
Properties are unchanged, so conn.prop is correct as well as conn.prop = val.
import asyncio
import aiomysql
async def test_example():
async with aiomysql.create_pool(host='127.0.0.1', port=3306,
user='root', password='',
db='mysql') as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 42;")
print(cur.description)
(r,) = await cur.fetchone()
assert r == 42
asyncio.run(test_example())
Example of SQLAlchemy optional integration
Sqlalchemy support has been ported from aiopg so api should be very familiar for aiopg user.:
import asyncio
import sqlalchemy as sa
from aiomysql.sa import create_engine
metadata = sa.MetaData()
tbl = sa.Table('tbl', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('val', sa.String(255)))
async def go():
engine = await create_engine(user='root', db='test_pymysql',
host='127.0.0.1', password='')
async with engine.acquire() as conn:
await conn.execute(tbl.insert().values(val='abc'))
await conn.execute(tbl.insert().values(val='xyz'))
async for row in conn.execute(tbl.select()):
print(row.id, row.val)
engine.close()
await engine.wait_closed()
asyncio.run(go())
Requirements
Release files for aiomysql 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiomysql-0.3.2.tar.gz | 108.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiomysql-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 180.1 kB
Release files / aiomysql-0.3.2.tar.gz
| Download URL | aiomysql-0.3.2.tar.gz |
|---|---|
| Size | 108.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72d15ef5cfc34c03468eb41e1b90adb9fd9347b0b589114bd23ead569a02ac1a
|
|
BLAKE2b-256 checksum How to use checksums |
29e0302aeffe8d90853556f47f3106b89c16cc2ec2a4d269bdfd82e3f4ae12cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2025.
Transparency logRelease files / aiomysql-0.3.2-py3-none-any.whl
| Download URL | aiomysql-0.3.2-py3-none-any.whl |
|---|---|
| Size | 71.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c82c5ba04137d7afd5c693a258bea8ead2aad77101668044143a991e04632eb2
|
|
BLAKE2b-256 checksum How to use checksums |
4cafaae0153c3e28712adaf462328f6c7a3c196a1c1c27b491de4377dd3e6b52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2025.
Transparency log