All Projects → long2ice → asyncmy

long2ice / asyncmy

Licence: Apache-2.0 license
A fast asyncio MySQL/MariaDB driver with replication protocol support

Programming Languages

python
139335 projects - #7 most used programming language
cython
566 projects
Makefile
30231 projects

Projects that are alternatives of or similar to asyncmy

kunlun-storage
Kunlun-storage is the storage component for KunlunBase. It's developed based on percona-mysql-8.0.x and contains exclusive features used by KunlunBase, performance enhancements and XA transaction crash safety enhancements without which MySQL would not be able to execute XA transactions reliably under error conditions such as power outage, proces…
Stars: ✭ 2 (-98.41%)
Mutual labels:  replication, binlog
horgh-replicator
Golang binlog replication from MySQL to MySQL, PostgreSQL, Vertica, Clickhouse
Stars: ✭ 46 (-63.49%)
Mutual labels:  replication, binlog
MySqlCdc
MySQL/MariaDB binlog replication client for .NET
Stars: ✭ 71 (-43.65%)
Mutual labels:  replication, binlog
spark-connector
A connector for Apache Spark to access Exasol
Stars: ✭ 13 (-89.68%)
Mutual labels:  connector
vrrm
rough code for running consensus
Stars: ✭ 18 (-85.71%)
Mutual labels:  replication
hyper-proxy
A proxy connector for Hyper-based crates
Stars: ✭ 73 (-42.06%)
Mutual labels:  connector
django-clone
Controlled Django model instance replication.
Stars: ✭ 89 (-29.37%)
Mutual labels:  replication
keda-connectors
Generic connectors for Keda which can be used as worker images as part of scaleTargetRef.
Stars: ✭ 22 (-82.54%)
Mutual labels:  connector
apsconnect-cli
Warning: EOL for January 2021. CloudBlue Connect CLI tool to automate APS Package management in the CloudBlue Commerce instance (hub).
Stars: ✭ 13 (-89.68%)
Mutual labels:  connector
backbeat
Zenko Backbeat is the core engine for asynchronous replication, optimized for queuing metadata updates and dispatching work to long-running tasks in the background.
Stars: ✭ 51 (-59.52%)
Mutual labels:  replication
Recon
HA LDAP based key/value solution for projects configuration storing with multi master replication support
Stars: ✭ 12 (-90.48%)
Mutual labels:  replication
mysqlbinlog-rs
A MySQL binlog file (row format) parser in Rust
Stars: ✭ 20 (-84.13%)
Mutual labels:  binlog
radiusd
Distributed Radius-server to do authentication+accounting.
Stars: ✭ 50 (-60.32%)
Mutual labels:  replication
data-transfer-hub
Seamless User Interface for replicating data into AWS.
Stars: ✭ 102 (-19.05%)
Mutual labels:  replication
replicator
MySQL Replicator. Replicates MySQL tables to Kafka and HBase, keeping the data changes history in HBase.
Stars: ✭ 41 (-67.46%)
Mutual labels:  binlog
DirectLineAndroidSample
Android Sample for Direct Line API - Microsoft Bot Framework
Stars: ✭ 21 (-83.33%)
Mutual labels:  connector
SupermarktConnector
Collecting product information from Dutch supermarkets: Albert Heijn and Jumbo using the Mobile API
Stars: ✭ 91 (-27.78%)
Mutual labels:  connector
pglogrepl
PostgreSQL logical replication library for Go.
Stars: ✭ 150 (+19.05%)
Mutual labels:  replication
Connectors
Connectors simplify connecting to standalone and CloudFoundry services
Stars: ✭ 28 (-77.78%)
Mutual labels:  connector
docker-mysql-replication
master master & master slave replication in mysql
Stars: ✭ 33 (-73.81%)
Mutual labels:  replication

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].