Skip to main content

MySQL driver for asyncio.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiomysql-0.3.2.tar.gz (108.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiomysql-0.3.2-py3-none-any.whl (71.8 kB view details)

Uploaded Python 3

File details

Details for the file aiomysql-0.3.2.tar.gz.

File metadata

  • Download URL: aiomysql-0.3.2.tar.gz
  • Upload date:
  • Size: 108.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiomysql-0.3.2.tar.gz
Algorithm Hash digest
SHA256 72d15ef5cfc34c03468eb41e1b90adb9fd9347b0b589114bd23ead569a02ac1a
MD5 b231ff658904964e25912f0e033f94e8
BLAKE2b-256 29e0302aeffe8d90853556f47f3106b89c16cc2ec2a4d269bdfd82e3f4ae12cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiomysql-0.3.2.tar.gz:

Publisher: ci-cd.yml on aio-libs/aiomysql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiomysql-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: aiomysql-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 71.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiomysql-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c82c5ba04137d7afd5c693a258bea8ead2aad77101668044143a991e04632eb2
MD5 1eb90e1db93899b15aaacf8f14573765
BLAKE2b-256 4cafaae0153c3e28712adaf462328f6c7a3c196a1c1c27b491de4377dd3e6b52

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiomysql-0.3.2-py3-none-any.whl:

Publisher: ci-cd.yml on aio-libs/aiomysql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page