Skip to main content

A fast asyncio MySQL driver

Project description

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.

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

asyncmy-0.2.2.tar.gz (61.4 kB view details)

Uploaded Source

Built Distributions

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

asyncmy-0.2.2-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

asyncmy-0.2.2-cp310-cp310-manylinux_2_31_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.31+ x86-64

asyncmy-0.2.2-cp310-cp310-macosx_10_15_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

asyncmy-0.2.2-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9Windows x86-64

asyncmy-0.2.2-cp39-cp39-manylinux_2_31_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.31+ x86-64

asyncmy-0.2.2-cp39-cp39-macosx_10_15_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

asyncmy-0.2.2-cp38-cp38-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.8Windows x86-64

asyncmy-0.2.2-cp38-cp38-manylinux_2_31_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

asyncmy-0.2.2-cp38-cp38-macosx_10_15_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

asyncmy-0.2.2-cp37-cp37m-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.7mWindows x86-64

asyncmy-0.2.2-cp37-cp37m-manylinux_2_31_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.31+ x86-64

asyncmy-0.2.2-cp37-cp37m-macosx_10_15_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

File details

Details for the file asyncmy-0.2.2.tar.gz.

File metadata

  • Download URL: asyncmy-0.2.2.tar.gz
  • Upload date:
  • Size: 61.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 84eeb0afbfd8eb1a8ad317d314f7bf1825aba0ba3e8132c48cbfbab1c287e62f
MD5 562b8fa3eba4296fff4719bf7e4ec89f
BLAKE2b-256 e1831eafc17ef47e2d0efa933520c0c19f0a54a3673892e4be4bda57e95379ef

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eece160770f259116c31cec8a1780c88c5d3496d217bb959bfc23229e9e03730
MD5 06606959897e29adaa627b5d150b5406
BLAKE2b-256 2208b6c4f1f09d9198c4dc15237034ecd3a9b7a01248ba368607dffc834475e0

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp310-cp310-manylinux_2_31_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp310-cp310-manylinux_2_31_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.10, manylinux: glibc 2.31+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d5913e1a330f92775d8fd1fe0df74d5cef6a488220506fd66698841a9ba5dc3c
MD5 4f3d0c62a8f4c818955e5462ed964376
BLAKE2b-256 a017886ce316e7d8f9e90e4f6f260b82e75f6d248c7d8aa47ef1ae142ac4db91

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp310-cp310-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.10, macOS 10.15+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0fb1573881deac1d078ec626df647dae6e7c7fae8f4255215c3ebdcb67085122
MD5 3f99a22e9f1ccabc87cfda6bd2282723
BLAKE2b-256 8384646514cdd70b488a5fc8053a1388804fbf1d924b1cc98b8fb26f2a6ea870

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 75a07404fa4de715f6d6e6d492d833c9ce2d4b00175db8589c69694b49ebc544
MD5 ff3d11c8c989014f17c16726adcecb16
BLAKE2b-256 904252a975373d04d61232c23f45ab856294ec6966633c9f533c513e28844420

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp39-cp39-manylinux_2_31_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp39-cp39-manylinux_2_31_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.9, manylinux: glibc 2.31+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp39-cp39-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 949531cb428d8b982244df0f9ad98dc906807439665cfc237e2a092c909ee72f
MD5 85435646fa3aa0995fb79b73ecdf229f
BLAKE2b-256 d5a2cca61cfe3752a32b43c59aefa00570ff5c4193b667ab524b71bad7e07669

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5b25f8166b29635402e1228c120785947c5cb9d3e8c94dc8b59e52d7a5ef7101
MD5 44437c7712b82f128cad2f5b859ed669
BLAKE2b-256 dc02226d62b5ef41c2527a5d6c07f1ac0374d3d40f380b96a422ba6699093017

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 2c9ebe0c1293fae9862ad89b16f5859bc8106b472c369dcaa9e0ca7e6e6c4699
MD5 89e7ded95602231f3d28ed3ea977d99a
BLAKE2b-256 965b403bc30fcde4cb4f76668e793a08a46a36448f3b861ae55026ec9e6a9f94

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp38-cp38-manylinux_2_31_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp38-cp38-manylinux_2_31_x86_64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.8, manylinux: glibc 2.31+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 0fbfc1c236309cad5e11352c1e94653d14e2ecc49a7264c20fba62b201fd90b1
MD5 a127f5c24ee0cf1931b4a98974049dc1
BLAKE2b-256 842167a5a3d91e8267b24c284ad0a5ecafee414dde14366043754276eeae7b59

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9e698f70bc61c617d07d7becabd81a13cb357f1fcc78a2f2da559b7dbd495469
MD5 4d19ed20db30e8e381154d2da7970a22
BLAKE2b-256 948bf652b0219c11b810745bf27b5aba83f32276189b46986dde17ecb224d0c9

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 2feecbac48f7082f0911bd8fc6ce4581fe9c691acc1c0691e11e3a98ae18b5ed
MD5 bc0af8263dd32a2490403606db120a07
BLAKE2b-256 399fd86ac33f778945dd91c20d4852806ae8b9ddc5b619fa2fc5040eb2948d84

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp37-cp37m-manylinux_2_31_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp37-cp37m-manylinux_2_31_x86_64.whl
  • Upload date:
  • Size: 4.0 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.31+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp37-cp37m-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 337ae4f903a8561265b64a3a3ef96e70de493fe149fbd4bb3c39aad146929ca4
MD5 91d015504bf54246b47b21491a74d24c
BLAKE2b-256 0e93bd16be874c5db7ac7878010ca0590044bebb72eed288edf6967b380d575b

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.2-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.2.2-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using 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

File hashes

Hashes for asyncmy-0.2.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 185e023f218e0601a563dc2788fa35307cd6b4f51afbb1a02d5dc41eec3b7602
MD5 409163dde75b4087e1407d1caa005106
BLAKE2b-256 430fbd47df094b6c676ffbf089d8f347cedc554c7575dcc14824a4405470ee94

See more details on using hashes here.

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