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

Features

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

Benchmark

The result comes from benchmark, we can know asyncmy performs well when compared to other drivers.

The device is MacBook Pro (13-inch, M1, 2020) 16G and MySQL version is 8.0.23.

benchmark

Install

Just install from pypi:

> pip install asyncmy

Usage

Use connect

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

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

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.1.9.tar.gz (60.4 kB view details)

Uploaded Source

Built Distribution

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

asyncmy-0.1.9-cp39-cp39-manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.9

File details

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

File metadata

  • Download URL: asyncmy-0.1.9.tar.gz
  • Upload date:
  • Size: 60.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.2 CPython/3.9.7

File hashes

Hashes for asyncmy-0.1.9.tar.gz
Algorithm Hash digest
SHA256 0fb48e77ba7ca77bc1797a95e9bd66167ff850a6b452da87a378108f4777747d
MD5 f9b28be0db74ba47d4c69d6a67a23293
BLAKE2b-256 bbc8a6f3046cfa5ef906bc74dcfb5bfc6d905c1f4c3a3e3825f0e079138515e2

See more details on using hashes here.

File details

Details for the file asyncmy-0.1.9-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: asyncmy-0.1.9-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.9
  • 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.2 CPython/3.9.7

File hashes

Hashes for asyncmy-0.1.9-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a07317f96f5506dfd35035db0d14901acf832655f61ddb4f417aa33c6998a7f
MD5 832ef37e4b7508c5f53039c40a4aa5d2
BLAKE2b-256 41ea89cea4d4c7f5d10aa5240a655e3fd8250567d4e3de58f2024081a3dbf733

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