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.5

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.5
File Size Uploaded
asyncmy-0.2.5.tar.gz 62.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for asyncmy 0.2.5
File
asyncmy-0.2.5-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
asyncmy-0.2.5-cp310-cp310-manylinux_2_31_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.31+ x86-64 Details
asyncmy-0.2.5-cp310-cp310-macosx_10_16_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.16+ x86-64 Details
asyncmy-0.2.5-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
asyncmy-0.2.5-cp39-cp39-manylinux_2_31_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.31+ x86-64 Details
asyncmy-0.2.5-cp39-cp39-macosx_10_16_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.16+ x86-64 Details
asyncmy-0.2.5-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
asyncmy-0.2.5-cp38-cp38-manylinux_2_31_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.31+ x86-64 Details
asyncmy-0.2.5-cp38-cp38-macosx_10_16_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.16+ x86-64 Details
asyncmy-0.2.5-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
asyncmy-0.2.5-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.5-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.5.tar.gz

Download URL asyncmy-0.2.5.tar.gz
Size 62.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cf3ef3d1ada385d231f23fffcbf1fe040bae8575b187746633fbef6e7cff2844
BLAKE2b-256 checksum
How to use checksums
421b2df423e2a55421944657d4bef462c674efc706a58bd815de516a809a0898
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.5-cp310-cp310-win_amd64.whl

Download URL asyncmy-0.2.5-cp310-cp310-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
9824184d180753d23101b1d9fdc7955783b08fbc6f3cc88d6acce7ff019c0eaf
BLAKE2b-256 checksum
How to use checksums
ca5768e75455e84ca789cf2aa8def2bee306c96420f7487a6120c7c6d7ac721e
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.5-cp310-cp310-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.5-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
f404d351d4f9fc741cdb8b49da8278e63a8551be6ccd03b514c2c0828500633d
BLAKE2b-256 checksum
How to use checksums
b655b4d50f7546f55d3ca15679b106e35ad1ae573118fc8337a7f5a2681046ab
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.5-cp310-cp310-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.5-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
f176b55c82d3bdb10f0ecb3a518a54777f3d247e00f06add138f63df4edc0e3d
BLAKE2b-256 checksum
How to use checksums
b445bb26129a0ac8a3694ef9a98d0d47d31e0172ec5778e2b03cd208a12eaff1
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.5-cp39-cp39-win_amd64.whl

Download URL asyncmy-0.2.5-cp39-cp39-win_amd64.whl
Size 1.4 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
f5dcc1a29d608cc5270f37328253032c554321b85bcf5653f1affa01f185c29c
BLAKE2b-256 checksum
How to use checksums
c14629abd6dd086fa6dec8bba05cb09ae35dbf65b7dd88c5ea529ca78dae6cf9
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.5-cp39-cp39-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.5-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
61ed1b9e69dafe476f02c20962b8ee4ec5ba130b760bdf504015fcb80bbe6787
BLAKE2b-256 checksum
How to use checksums
ec1c2bd62723e9ac14825e1e54e6fd76ddfddc72d2a2ecd30c7a050666f5c4da
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.5-cp39-cp39-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.5-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
6606e296dc161d71629f1163c3c82dda97431e25ee7240b6b7f139c2c35cff94
BLAKE2b-256 checksum
How to use checksums
f9a29c46036d77bfbd6f918384f9fc94fcb8d938533918350c7f08311ba7f8c7
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.5-cp38-cp38-win_amd64.whl

Download URL asyncmy-0.2.5-cp38-cp38-win_amd64.whl
Size 1.4 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
527ccc24a9bd76d565f1024f4a50ee6fd92cac518e6d884281ad61ffc424e7cd
BLAKE2b-256 checksum
How to use checksums
f347702fe8952d68ef1363128ef6eca765549b499bd43a1aa0931ef502832450
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.5-cp38-cp38-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.5-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
2275cc0036fa39f888c0770173ffb8ed16b89eecf2e380499275bfa6bf4ee088
BLAKE2b-256 checksum
How to use checksums
5c984e4ba25000be46a9295964643406142fd1147ca91fd7be4d2824db111b15
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.5-cp38-cp38-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.5-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
e184e701fa153dd456f6b351136c0a7a7524b8f5959f7f4b47848efe434a9c7d
BLAKE2b-256 checksum
How to use checksums
9ab477337bb6c1fb7ed8d1a2e6581c76481c43fa8b54205d2790c80983e538ab
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.5-cp37-cp37m-win_amd64.whl

Download URL asyncmy-0.2.5-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
2dc25f0bb723a71445d5c5b46ab2ae71c9dd3123fea9eae1bee4c36af5eda2bc
BLAKE2b-256 checksum
How to use checksums
7c041cd560e30dd64cda89bee5fe64af19781809e36755289720737e9866b9ae
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.5-cp37-cp37m-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.5-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
a341d8a22d9a1f3236a81f17836002291567aa7d878ab75b37ed9bf4ce401290
BLAKE2b-256 checksum
How to use checksums
8c91be0f6c865c3b54413f8620a229a6e1c7bf9944120c956e8a636e5036a488
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.5-cp37-cp37m-macosx_10_16_x86_64.whl

Download URL asyncmy-0.2.5-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
02add8063bd00762a469dcb9915563f66520ffda598851a957443b1012182f43
BLAKE2b-256 checksum
How to use checksums
3ae86da7c7a096a74dfdde83602363d8917e9706b131e3895e6b43f9037b31a1
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