Skip to main content

aiomysql

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

Metadata

Release files for aiomysql 0.3.1

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.1
File Size Uploaded
aiomysql-0.3.1.tar.gz 108.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiomysql 0.3.1
File Interpreter ABI Platform
aiomysql-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 180.1 kB

Release files / aiomysql-0.3.1.tar.gz

Download URL aiomysql-0.3.1.tar.gz
Size 108.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1457a0111500c4158ad5138120f0a2e91ea2c26cc653199e35058d78a5db53e1
BLAKE2b-256 checksum
How to use checksums
44698ce807db1da7b80f526ed9793f3a938cd88bf4350f8008909a258f22e779
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 21, 2025.

Transparency log

Release files / aiomysql-0.3.1-py3-none-any.whl

Download URL aiomysql-0.3.1-py3-none-any.whl
Size 71.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56cc6925c8f10b9c61cfee1c514ff53fd6a22530c6e8b04cccfe9c62ac5ba884
BLAKE2b-256 checksum
How to use checksums
2a43399c7c67641ce68f6e13badcd8fdbeb8da2cd269b5e1b783156f592f28a8
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 21, 2025.

Transparency log

Release history Release notifications | RSS feed

0.3.2

2 release files

This release

0.3.1 This release

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