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

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.3
File Size Uploaded Provenance Actions
asyncmy-0.2.3.tar.gz 62.7 kB Without provenance Details for asyncmy-0.2.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for asyncmy 0.2.3
File Actions
asyncmy-0.2.3-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for asyncmy-0.2.3-cp310-cp310-win_amd64.whl
asyncmy-0.2.3-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.3-cp310-cp310-manylinux_2_31_x86_64.whl
asyncmy-0.2.3-cp310-cp310-macosx_10_15_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.15+ x86-64 Details for asyncmy-0.2.3-cp310-cp310-macosx_10_15_x86_64.whl
asyncmy-0.2.3-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for asyncmy-0.2.3-cp39-cp39-win_amd64.whl
asyncmy-0.2.3-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.3-cp39-cp39-manylinux_2_31_x86_64.whl
asyncmy-0.2.3-cp39-cp39-macosx_10_15_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.15+ x86-64 Details for asyncmy-0.2.3-cp39-cp39-macosx_10_15_x86_64.whl
asyncmy-0.2.3-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details for asyncmy-0.2.3-cp38-cp38-win_amd64.whl
asyncmy-0.2.3-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.3-cp38-cp38-manylinux_2_31_x86_64.whl
asyncmy-0.2.3-cp38-cp38-macosx_10_15_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.15+ x86-64 Details for asyncmy-0.2.3-cp38-cp38-macosx_10_15_x86_64.whl
asyncmy-0.2.3-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for asyncmy-0.2.3-cp37-cp37m-win_amd64.whl
asyncmy-0.2.3-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.3-cp37-cp37m-manylinux_2_31_x86_64.whl
asyncmy-0.2.3-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.3-cp37-cp37m-macosx_10_15_x86_64.whl

Total release size: 29.5 MB

Release files / asyncmy-0.2.3.tar.gz

Download URL asyncmy-0.2.3.tar.gz
Size 62.7 kB
Tags Source
SHA-256 checksum
How to use checksums
769f749d8b03b28a31b185b77c54e8f8f363ee8a3c3719bad8a71e4e9a0ce8a6
BLAKE2b-256 checksum
How to use checksums
08454dd47dd62d15a6b8603a5d1eed0b72040105147d4e935d21ff11ba5d6442
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.3-cp310-cp310-win_amd64.whl

Download URL asyncmy-0.2.3-cp310-cp310-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
2b6dbfe7f4f7ffbcaa190f477f79361cbbc79248eeb05ee8c338b295b18a0119
BLAKE2b-256 checksum
How to use checksums
29f06674364ddbca9b2d164f398a33e4ea0a3bba0041370625edd7006c84c306
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.3-cp310-cp310-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.3-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
38d6c2e658d13213ced685b5e41e35df1122174423b38f2bc27a6a4535de05b2
BLAKE2b-256 checksum
How to use checksums
33b9ad611de1b3182f957fde0e473398f641c5c73d81402005aef6c2fc03a4d5
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.3-cp310-cp310-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.3-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
c9dc38b56e3091d75ccda1ed598f90dac0489f4e6700bb3aae89b9a8b4635ad3
BLAKE2b-256 checksum
How to use checksums
1d46d294d3c0559d53d113c6717734f9f7138dd55169850b60e6263dc16694d8
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.3-cp39-cp39-win_amd64.whl

Download URL asyncmy-0.2.3-cp39-cp39-win_amd64.whl
Size 1.4 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
5577b695c38e01377e7ef4f5bd3877aada11d1174f80b6354be55a5447f9d1f8
BLAKE2b-256 checksum
How to use checksums
86d47d1f885a3ee2aeea022bfe6da2b0c427d57e4f47e5e62fd42963ca07617a
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.3-cp39-cp39-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.3-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
3167337d2e778b560fc109ec9d388562b4e9b0241e6d31ca2de15bf7437c781d
BLAKE2b-256 checksum
How to use checksums
2c9c2aea1a25448709c75988248c030ee6704dc067c38a045dd6aee42bc7f85d
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.3-cp39-cp39-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.3-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
4be0f01f79974adf7c064c3c23bd30cd24627c081a39a03461bd4fea0a59562b
BLAKE2b-256 checksum
How to use checksums
37f270d371ad4ded2733d5f745e72ba0a7b85943a2726e795482c50114ea35cf
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.3-cp38-cp38-win_amd64.whl

Download URL asyncmy-0.2.3-cp38-cp38-win_amd64.whl
Size 1.4 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
804fda2c96e16de5b4a7740a49cf21207fe6b856875608f28a75a486e4903b3d
BLAKE2b-256 checksum
How to use checksums
8dac9e7812e2765a7c9734f96ba3b98e3b24e22bd66236a3ded0b33b186c996b
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.3-cp38-cp38-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.3-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
ef785957e480902d9b1a34f23e29157de84606bf758ddbfbabc1afe93f91ece3
BLAKE2b-256 checksum
How to use checksums
feaccbf4e41aea0749c69551f58bf215e23bc57638cf2646c19bd844955dfa64
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.3-cp38-cp38-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.3-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
2b14ebd0c1e050a6ee0a314111527327fdb53fe490169af6ed9361a921fba2fa
BLAKE2b-256 checksum
How to use checksums
23b7ee9ac7f65f6ae294aab5ce44ff02c71902328e0966945476a5efac24d475
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.3-cp37-cp37m-win_amd64.whl

Download URL asyncmy-0.2.3-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
22ab5de34356a7331443d0076c47c78aedd3b1c41e1b6baf4017b2f207fd39d4
BLAKE2b-256 checksum
How to use checksums
d21852fb46b9fefc2c6c59116d7c54fd1ab6aac810cccb81063ed846c0e9e213
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.3-cp37-cp37m-manylinux_2_31_x86_64.whl

Download URL asyncmy-0.2.3-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
0c7db0d0b7c0f47fcb656c1db41f5845b3a5e7e83013264c83e943e53c4abb60
BLAKE2b-256 checksum
How to use checksums
26d34bf8b71816db2fbc4e0d69d4af1514857bcd7165e33867d72e1a69fcfabc
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.3-cp37-cp37m-macosx_10_15_x86_64.whl

Download URL asyncmy-0.2.3-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
28a534ceab5fbc2e20a29b2167c05c94f2cc1e2735a96fcc24b684890bb1109a
BLAKE2b-256 checksum
How to use checksums
d255511b407d1ff21434f3afeede4481c6e2ee7e6f57f9732032b2e85ad997d1
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.3

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