Skip to main content

A fast asyncio MySQL driver

Project description

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.

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.4.tar.gz (62.9 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.4-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

asyncmy-0.2.4-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.4-cp310-cp310-macosx_10_16_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10macOS 10.16+ x86-64

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

Uploaded CPython 3.9Windows x86-64

asyncmy-0.2.4-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.4-cp39-cp39-macosx_10_16_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9macOS 10.16+ x86-64

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

Uploaded CPython 3.8Windows x86-64

asyncmy-0.2.4-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.4-cp38-cp38-macosx_10_16_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8macOS 10.16+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

asyncmy-0.2.4-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.4-cp37-cp37m-macosx_10_16_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7mmacOS 10.16+ x86-64

File details

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

File metadata

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

File hashes

Hashes for asyncmy-0.2.4.tar.gz
Algorithm Hash digest
SHA256 aa0639fcfea7db47e7b1c8cca4e5c30bfd597b8722c3f9df296eaded656758ed
MD5 6490dbe64aeed9263b771d8043fe21e4
BLAKE2b-256 2c7c5f7132c74303172ca4bdcdc37678b494027810e14b57aa746ebce8069b96

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e79d139cab4e31d7ec9eac9d49d471c13e5648c2cd3a8212d04bdbedba2cd717
MD5 901266a5620d3eab131786d725421a36
BLAKE2b-256 9dbd5a3d33dfca25023679400b9047fb55923e4636e0cfa593f3356507d2e440

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 59c625aa4a43727cb3e7dd55338eba52af900be018552eaf9b5747a7ba29dcc1
MD5 cb57803d3f8c1057e7ea71de01e9ac35
BLAKE2b-256 aee665ee9b21cf81aea0075b8ce6ac0da9a686457edd9feb5b3eeceb07fbef75

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.4-cp310-cp310-macosx_10_16_x86_64.whl.

File metadata

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

File hashes

Hashes for asyncmy-0.2.4-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 191541afca78096b31f0b4d431d41b8c60074649193d4166ef01dfb78113b6b2
MD5 d14fec600e1b3f50688a7ec336457475
BLAKE2b-256 82d6c212ab00587c9649ec57877b22c7174738b71c04e914dc34e09c651b347d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 012a79e4c3045ea2da23bb80d57dc659aad148d0a6b48abacfac31fdc858cf94
MD5 909ef140fb32f3ae41a5ef61491c5bb1
BLAKE2b-256 b236a25cfbd98af473e38e6c0d05ef72c4d797c84aef6fcb8271748fd1d94906

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp39-cp39-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 5697237913c2913b94f1908a76c880fb110e35532acfc50fa6578113ce8f4bfb
MD5 fa57c634df2fee204bd76898452e6ab8
BLAKE2b-256 0c1304eda9339af5adc5d8586f4e2268eed67f6b1ff3f17d1b1383c23364c2a8

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.4-cp39-cp39-macosx_10_16_x86_64.whl.

File metadata

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

File hashes

Hashes for asyncmy-0.2.4-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 3d7d8cead8abbfe53efc80386302f320a3a1a66b00e0666f15f52a467264ff5b
MD5 632decdad8bde96e0109824ac125458c
BLAKE2b-256 8524b98efcc1116428c32e15f89ab0d84ca079740660e832c83ca994e40d2666

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9a55a64d3753d3d0e000ae660ec0ea15f0e314f42cfab0fc43dbfbb7f6ea96ce
MD5 68d135c74a5aa96b435b9c7a7fbae2ad
BLAKE2b-256 916b8c943a3513efad0e3fd60b216ffd4d906e75b1f4ac5e5f61dda20dfde068

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 5712cd74d4bc95d047235744e5c5d14b3e835bcbdd141a2e5c4b2255ca81f2c7
MD5 ed9484fb92ab22ad0f3db3800221d5c1
BLAKE2b-256 5cef71ae837fec424c20fe7406b9ce818e8529b183ba84a9a10b8512a3151eeb

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.4-cp38-cp38-macosx_10_16_x86_64.whl.

File metadata

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

File hashes

Hashes for asyncmy-0.2.4-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 c1002b59ea568c96fc9dc8b3d7744dfcdbc2f7a2c64070844ce5f00d209ae428
MD5 87c52a51db13cc90643205916d2a2641
BLAKE2b-256 a2541f2343fa0116c499de69f562e2da8373583bd7196113cc8a7fa0e8350ab5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 f38d167d0ce441125174a7357a9e72771b97e35739fd46c517c5f38be0bb2355
MD5 e931d84ca56623e8c32b1bbf663a42b3
BLAKE2b-256 2f46f1f8368774db0c185f8fab048362a90787636532ca6a9bcdb3a786decb74

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncmy-0.2.4-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.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

File hashes

Hashes for asyncmy-0.2.4-cp37-cp37m-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 7096d3bce1612fcb78117944fd3279e32959c010b483c3eba22abde1a9f8905d
MD5 c572e74e06cc4ceeb567c1781c4e82aa
BLAKE2b-256 6c00d391faffc76eaf5b24117a3cfb08001d6b60fa34c8b50ab036a77ce46045

See more details on using hashes here.

File details

Details for the file asyncmy-0.2.4-cp37-cp37m-macosx_10_16_x86_64.whl.

File metadata

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

File hashes

Hashes for asyncmy-0.2.4-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 30a12e4f11adca65180400ab2b088afe02a43cf0f94c6b76fc329d565f5902c9
MD5 d617b35126c8e016a6f93896eea5e4ed
BLAKE2b-256 2e16e3fcf5437d1814193479b5bb2d60ae6687630011ba4f539344f76d3c1d8b

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