Skip to main content
https://github.com/aio-libs/aiomysql/actions/workflows/ci-cd.yml/badge.svg?branch=main Code coverage Latest Version Documentation Status Chat on Gitter

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

https://aiomysql.readthedocs.io/

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)

Source distribution for aiomysql 0.3.2
File Size Uploaded
aiomysql-0.3.2.tar.gz 108.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiomysql 0.3.2
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.15

1 release file

0.0.14

1 release file

0.0.13

1 release file

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page