Skip to main content

asyncmy - A fast asyncio MySQL driver

image image pypi ci

Introduction

asyncmy is a fast asyncio MySQL driver, which reuse most of pymysql and rewrite core with cython to speedup.

Features

  • API compatible with aiomysql.
  • Fast with cython.
  • MySQL replication protocol support.

Benchmark

The result comes from benchmark, we can know asyncmy performs well when compared to other drivers.

The device is MacBook Pro (13-inch, M1, 2020) 16G and MySQL version is 8.0.23.

benchmark

Install

Just install from pypi:

> pip install asyncmy

Usage

Use connect

from asyncmy import connect
from asyncmy.cursors import DictCursor
import asyncio


async def run():
    conn = await connect()
    async with conn.cursor(cursor=DictCursor) as cursor:
        await cursor.execute("create database if not exists test")
        await cursor.execute(
            """CREATE TABLE if not exists test.asyncmy
    (
        `id`       int primary key auto_increment,
        `decimal`  decimal(10, 2),
        `date`     date,
        `datetime` datetime,
        `float`    float,
        `string`   varchar(200),
        `tinyint`  tinyint
    )"""
        )


if __name__ == '__main__':
    asyncio.run(run())

Use pool

import asyncmy
import asyncio


async def run():
    pool = await asyncmy.create_pool()
    async with pool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute("SELECT 1")
            ret = await cursor.fetchone()
            assert ret == (1,)


if __name__ == '__main__':
    asyncio.run(run())

Replication

from asyncmy import connect
from asyncmy.replication import BinLogStream
import asyncio


async def run():
    conn = await connect()
    ctl_conn = await connect()

    stream = BinLogStream(
        conn,
        ctl_conn,
        1,
        master_log_file="binlog.000172",
        master_log_position=2235312,
        resume_stream=True,
        blocking=True,
    )
    await stream.connect()
    async for event in stream:
        print(event)


if __name__ == '__main__':
    asyncio.run(run())

ThanksTo

asyncmy is build on top of these nice projects.

  • pymysql, a pure python MySQL client.
  • aiomysql, a library for accessing a MySQL database from the asyncio.
  • python-mysql-replication, pure Python Implementation of MySQL replication protocol build on top of PyMYSQL.

License

This project is licensed under the Apache-2.0 License.

Metadata

Release files for asyncmy 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncmy 0.1.6
File Size Uploaded
asyncmy-0.1.6.tar.gz 60.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncmy 0.1.6
File Interpreter ABI Platform
asyncmy-0.1.6-cp39-cp39-manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details

Total release size: 3.1 MB

Release files / asyncmy-0.1.6.tar.gz

Download URL asyncmy-0.1.6.tar.gz
Size 60.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7362d27fe31ee144a9454b59566fdb5f88216cb22e7513bbce37320fdf8b62e2
BLAKE2b-256 checksum
How to use checksums
02e2df9669ada159c1c9769fc280ef98c9892836427200df1ae712dc0955d764
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Release files / asyncmy-0.1.6-cp39-cp39-manylinux2014_x86_64.whl

Download URL asyncmy-0.1.6-cp39-cp39-manylinux2014_x86_64.whl
Size 3.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
184af2f4812e6710454ff0c37af32584a493f56ac38d97c4946098b79d9176da
BLAKE2b-256 checksum
How to use checksums
279cc315d4cf28d58ec6816b50ff691ea524bfa553e467330bca6ce2d9a7c8b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
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