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 aiomysql but rewrite core protocol with cython to speedup.

Features

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

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

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.2
File Size Uploaded Provenance Actions
asyncmy-0.2.2.tar.gz 61.4 kB Without provenance Details for asyncmy-0.2.2.tar.gz

Built distributions (wheels)

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

Total release size: 29.4 MB

Release files / asyncmy-0.2.2.tar.gz

Download URL asyncmy-0.2.2.tar.gz
Size 61.4 kB
Tags Source
SHA-256 checksum
How to use checksums
84eeb0afbfd8eb1a8ad317d314f7bf1825aba0ba3e8132c48cbfbab1c287e62f
BLAKE2b-256 checksum
How to use checksums
e1831eafc17ef47e2d0efa933520c0c19f0a54a3673892e4be4bda57e95379ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-cp310-cp310-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
eece160770f259116c31cec8a1780c88c5d3496d217bb959bfc23229e9e03730
BLAKE2b-256 checksum
How to use checksums
2208b6c4f1f09d9198c4dc15237034ecd3a9b7a01248ba368607dffc834475e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-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
d5913e1a330f92775d8fd1fe0df74d5cef6a488220506fd66698841a9ba5dc3c
BLAKE2b-256 checksum
How to use checksums
a017886ce316e7d8f9e90e4f6f260b82e75f6d248c7d8aa47ef1ae142ac4db91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / asyncmy-0.2.2-cp310-cp310-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.2-cp310-cp310-macosx_10_15_x86_64.whl
Size 1.5 MB
Tags CPython 3.10 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
0fb1573881deac1d078ec626df647dae6e7c7fae8f4255215c3ebdcb67085122
BLAKE2b-256 checksum
How to use checksums
8384646514cdd70b488a5fc8053a1388804fbf1d924b1cc98b8fb26f2a6ea870
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-cp39-cp39-win_amd64.whl
Size 1.4 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
75a07404fa4de715f6d6e6d492d833c9ce2d4b00175db8589c69694b49ebc544
BLAKE2b-256 checksum
How to use checksums
904252a975373d04d61232c23f45ab856294ec6966633c9f533c513e28844420
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-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
949531cb428d8b982244df0f9ad98dc906807439665cfc237e2a092c909ee72f
BLAKE2b-256 checksum
How to use checksums
d5a2cca61cfe3752a32b43c59aefa00570ff5c4193b667ab524b71bad7e07669
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / asyncmy-0.2.2-cp39-cp39-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.2-cp39-cp39-macosx_10_15_x86_64.whl
Size 1.5 MB
Tags CPython 3.9 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
5b25f8166b29635402e1228c120785947c5cb9d3e8c94dc8b59e52d7a5ef7101
BLAKE2b-256 checksum
How to use checksums
dc02226d62b5ef41c2527a5d6c07f1ac0374d3d40f380b96a422ba6699093017
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-cp38-cp38-win_amd64.whl
Size 1.4 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
2c9ebe0c1293fae9862ad89b16f5859bc8106b472c369dcaa9e0ca7e6e6c4699
BLAKE2b-256 checksum
How to use checksums
965b403bc30fcde4cb4f76668e793a08a46a36448f3b861ae55026ec9e6a9f94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-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
0fbfc1c236309cad5e11352c1e94653d14e2ecc49a7264c20fba62b201fd90b1
BLAKE2b-256 checksum
How to use checksums
842167a5a3d91e8267b24c284ad0a5ecafee414dde14366043754276eeae7b59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / asyncmy-0.2.2-cp38-cp38-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.2-cp38-cp38-macosx_10_15_x86_64.whl
Size 1.5 MB
Tags CPython 3.8 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
9e698f70bc61c617d07d7becabd81a13cb357f1fcc78a2f2da559b7dbd495469
BLAKE2b-256 checksum
How to use checksums
948bf652b0219c11b810745bf27b5aba83f32276189b46986dde17ecb224d0c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-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
2feecbac48f7082f0911bd8fc6ce4581fe9c691acc1c0691e11e3a98ae18b5ed
BLAKE2b-256 checksum
How to use checksums
399fd86ac33f778945dd91c20d4852806ae8b9ddc5b619fa2fc5040eb2948d84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

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

Download URL asyncmy-0.2.2-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
337ae4f903a8561265b64a3a3ef96e70de493fe149fbd4bb3c39aad146929ca4
BLAKE2b-256 checksum
How to use checksums
0e93bd16be874c5db7ac7878010ca0590044bebb72eed288edf6967b380d575b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / asyncmy-0.2.2-cp37-cp37m-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.2-cp37-cp37m-macosx_10_15_x86_64.whl
Size 1.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
185e023f218e0601a563dc2788fa35307cd6b4f51afbb1a02d5dc41eec3b7602
BLAKE2b-256 checksum
How to use checksums
430fbd47df094b6c676ffbf089d8f347cedc554c7575dcc14824a4405470ee94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for asyncmy 0.2.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.2 This release

13 release files No provenance

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