Giter VIP home page Giter VIP logo

asyncmy's Introduction

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,
    )
    await stream.connect()
    async for event in stream:
        print(event)


if __name__ == '__main__':
    asyncio.run(run())

ThanksTo

asyncmy is build on top of these nice 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.

asyncmy's People

Contributors

long2ice avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.