Skip to main content

asyncmy - A fast asyncio MySQL/MariaDB driver

image image pypi ci

Introduction

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

Features

  • API compatible with aiomysql.
  • Faster by cython.
  • MySQL replication protocol support with asyncio.
  • Tested both MySQL and MariaDB in CI.

Benchmark

The result comes from benchmark.

The device is iMac Pro(2017) i9 3.6GHz 48G and MySQL version is 8.0.26.

benchmark

Conclusion

  • There is no doubt that mysqlclient is the fastest MySQL driver.
  • All kinds of drivers have a small gap except select.
  • asyncio could enhance insert.
  • asyncmy performs remarkable when compared to other drivers.

Install

pip install asyncmy

Installing on Windows

To install asyncmy on Windows, you need to install the tools needed to build it.

  1. Download Microsoft C++ Build Tools from https://visualstudio.microsoft.com/visual-cpp-build-tools/
  2. Run CMD as Admin (not required but recommended) and navigate to the folder when your installer is downloaded
  3. Installer executable should look like this vs_buildtools__XXXXXXXXX.XXXXXXXXXX.exe, it will be easier if you rename it to just vs_buildtools.exe
  4. Run this command (Make sure you have about 5-6GB of free storage)
vs_buildtools.exe --norestart --passive --downloadThenInstall --includeRecommended --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools
  1. Wait until the installation is finished
  2. After installation will finish, restart your computer
  3. Install asyncmy via PIP
pip install asyncmy

Now you can uninstall previously installed tools.

Usage

Use connect

asyncmy provides a way to connect to MySQL database with simple factory function asyncmy.connnect(). Use this function if you want just one connection to the database, consider connection pool for multiple connections.

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

asyncmy provides connection pool as well as plain Connection objects.

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

asyncmy supports MySQL replication protocol like python-mysql-replication, but powered by asyncio.

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,
    )
    async for event in stream:
        print(event)


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

ThanksTo

asyncmy is build on top of these awesome 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.2.4

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.2.4
File Size Uploaded
asyncmy-0.2.4.tar.gz 62.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for asyncmy 0.2.4
File
asyncmy-0.2.4-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
asyncmy-0.2.4-cp310-cp310-manylinux_2_31_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.31+ x86-64 Details
asyncmy-0.2.4-cp310-cp310-macosx_10_16_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.16+ x86-64 Details
asyncmy-0.2.4-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
asyncmy-0.2.4-cp39-cp39-manylinux_2_31_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.31+ x86-64 Details
asyncmy-0.2.4-cp39-cp39-macosx_10_16_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.16+ x86-64 Details
asyncmy-0.2.4-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
asyncmy-0.2.4-cp38-cp38-manylinux_2_31_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.31+ x86-64 Details
asyncmy-0.2.4-cp38-cp38-macosx_10_16_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.16+ x86-64 Details
asyncmy-0.2.4-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
asyncmy-0.2.4-cp37-cp37m-manylinux_2_31_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.31+ x86-64 Details
asyncmy-0.2.4-cp37-cp37m-macosx_10_16_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.16+ x86-64 Details

Total release size: 29.6 MB

Release files / asyncmy-0.2.4.tar.gz

Download URL asyncmy-0.2.4.tar.gz
Size 62.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aa0639fcfea7db47e7b1c8cca4e5c30bfd597b8722c3f9df296eaded656758ed
BLAKE2b-256 checksum
How to use checksums
2c7c5f7132c74303172ca4bdcdc37678b494027810e14b57aa746ebce8069b96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp310-cp310-win_amd64.whl

Download URL asyncmy-0.2.4-cp310-cp310-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
e79d139cab4e31d7ec9eac9d49d471c13e5648c2cd3a8212d04bdbedba2cd717
BLAKE2b-256 checksum
How to use checksums
9dbd5a3d33dfca25023679400b9047fb55923e4636e0cfa593f3356507d2e440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp310-cp310-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.4-cp310-cp310-manylinux_2_31_x86_64.whl
Size 4.4 MB
Tags CPython 3.10 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
59c625aa4a43727cb3e7dd55338eba52af900be018552eaf9b5747a7ba29dcc1
BLAKE2b-256 checksum
How to use checksums
aee665ee9b21cf81aea0075b8ce6ac0da9a686457edd9feb5b3eeceb07fbef75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp310-cp310-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.4-cp310-cp310-macosx_10_16_x86_64.whl
Size 1.5 MB
Tags CPython 3.10 macOS 10.16+ x86-64
SHA-256 checksum
How to use checksums
191541afca78096b31f0b4d431d41b8c60074649193d4166ef01dfb78113b6b2
BLAKE2b-256 checksum
How to use checksums
82d6c212ab00587c9649ec57877b22c7174738b71c04e914dc34e09c651b347d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp39-cp39-win_amd64.whl

Download URL asyncmy-0.2.4-cp39-cp39-win_amd64.whl
Size 1.4 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
012a79e4c3045ea2da23bb80d57dc659aad148d0a6b48abacfac31fdc858cf94
BLAKE2b-256 checksum
How to use checksums
b236a25cfbd98af473e38e6c0d05ef72c4d797c84aef6fcb8271748fd1d94906
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp39-cp39-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.4-cp39-cp39-manylinux_2_31_x86_64.whl
Size 4.4 MB
Tags CPython 3.9 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
5697237913c2913b94f1908a76c880fb110e35532acfc50fa6578113ce8f4bfb
BLAKE2b-256 checksum
How to use checksums
0c1304eda9339af5adc5d8586f4e2268eed67f6b1ff3f17d1b1383c23364c2a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp39-cp39-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.4-cp39-cp39-macosx_10_16_x86_64.whl
Size 1.5 MB
Tags CPython 3.9 macOS 10.16+ x86-64
SHA-256 checksum
How to use checksums
3d7d8cead8abbfe53efc80386302f320a3a1a66b00e0666f15f52a467264ff5b
BLAKE2b-256 checksum
How to use checksums
8524b98efcc1116428c32e15f89ab0d84ca079740660e832c83ca994e40d2666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp38-cp38-win_amd64.whl

Download URL asyncmy-0.2.4-cp38-cp38-win_amd64.whl
Size 1.4 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
9a55a64d3753d3d0e000ae660ec0ea15f0e314f42cfab0fc43dbfbb7f6ea96ce
BLAKE2b-256 checksum
How to use checksums
916b8c943a3513efad0e3fd60b216ffd4d906e75b1f4ac5e5f61dda20dfde068
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp38-cp38-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.4-cp38-cp38-manylinux_2_31_x86_64.whl
Size 4.9 MB
Tags CPython 3.8 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
5712cd74d4bc95d047235744e5c5d14b3e835bcbdd141a2e5c4b2255ca81f2c7
BLAKE2b-256 checksum
How to use checksums
5cef71ae837fec424c20fe7406b9ce818e8529b183ba84a9a10b8512a3151eeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp38-cp38-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.4-cp38-cp38-macosx_10_16_x86_64.whl
Size 1.5 MB
Tags CPython 3.8 macOS 10.16+ x86-64
SHA-256 checksum
How to use checksums
c1002b59ea568c96fc9dc8b3d7744dfcdbc2f7a2c64070844ce5f00d209ae428
BLAKE2b-256 checksum
How to use checksums
a2541f2343fa0116c499de69f562e2da8373583bd7196113cc8a7fa0e8350ab5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp37-cp37m-win_amd64.whl

Download URL asyncmy-0.2.4-cp37-cp37m-win_amd64.whl
Size 1.4 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
f38d167d0ce441125174a7357a9e72771b97e35739fd46c517c5f38be0bb2355
BLAKE2b-256 checksum
How to use checksums
2f46f1f8368774db0c185f8fab048362a90787636532ca6a9bcdb3a786decb74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp37-cp37m-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.4-cp37-cp37m-manylinux_2_31_x86_64.whl
Size 4.0 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
7096d3bce1612fcb78117944fd3279e32959c010b483c3eba22abde1a9f8905d
BLAKE2b-256 checksum
How to use checksums
6c00d391faffc76eaf5b24117a3cfb08001d6b60fa34c8b50ab036a77ce46045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / asyncmy-0.2.4-cp37-cp37m-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.4-cp37-cp37m-macosx_10_16_x86_64.whl
Size 1.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.16+ x86-64
SHA-256 checksum
How to use checksums
30a12e4f11adca65180400ab2b088afe02a43cf0f94c6b76fc329d565f5902c9
BLAKE2b-256 checksum
How to use checksums
2e16e3fcf5437d1814193479b5bb2d60ae6687630011ba4f539344f76d3c1d8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12
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