Package: asyncmy
asyncmy - A fast asyncio MySQL/MariaDB driverIntroductionasyncmyis a fast asyncio MySQL/MariaDB driver, which reuse most ofpymysqlandaiomysqlbut rewrite core protocol withcythonto
speedup.FeaturesAPI compatible withaiomysql.Faster bycython.MySQL replication protocol support withasyncio.Tested both MySQL and MariaDB inCI.BenchmarkThe result comes frombenchmark.The device is iMac Pro(2017) i9 3.6GHz 48G and MySQL version is 8.0.26.ConclusionThere is no doubt thatmysqlclientis the fastest MySQL driver.All kinds of drivers have a small gap exceptselect.asynciocould enhanceinsert.asyncmyperforms remarkable when compared to other drivers.InstallpipinstallasyncmyInstalling on WindowsTo install asyncmy on Windows, you need to install the tools needed to build it.DownloadMicrosoft C++ Build Toolsfromhttps://visualstudio.microsoft.com/visual-cpp-build-tools/Run CMD as Admin (not required but recommended) and navigate to the folder when your installer is downloadedInstaller executable should look like thisvs_buildtools__XXXXXXXXX.XXXXXXXXXX.exe, it will be easier if you rename
it to justvs_buildtools.exeRun this command (Make sure you have about 5-6GB of free storage)vs_buildtools.exe--norestart--passive--downloadThenInstall--includeRecommended--addMicrosoft.VisualStudio.Workload.NativeDesktop--addMicrosoft.VisualStudio.Workload.VCTools--addMicrosoft.VisualStudio.Workload.MSBuildToolsWait until the installation is finishedAfter installation will finish, restart your computerInstall asyncmy via PIPpipinstallasyncmyNow you can uninstall previously installed tools.UsageUseconnectasyncmyprovides a way to connect to MySQL database with simple factory functionasyncmy.connect(). Use this
function if you want just one connection to the database, consider connection pool for multiple connections.fromasyncmyimportconnectfromasyncmy.cursorsimportDictCursorimportasyncioasyncdefrun():conn=awaitconnect()asyncwithconn.cursor(cursor=DictCursor)ascursor:awaitcursor.execute("create database if not exists test")awaitcursor.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())Usepoolasyncmyprovides connection pool as well as plain Connection objects.importasyncmyimportasyncioasyncdefrun():pool=awaitasyncmy.create_pool()asyncwithpool.acquire()asconn:asyncwithconn.cursor()ascursor:awaitcursor.execute("SELECT 1")ret=awaitcursor.fetchone()assertret==(1,)if__name__=='__main__':asyncio.run(run())Replicationasyncmysupports MySQL replication protocol
likepython-mysql-replication, but powered byasyncio.fromasyncmyimportconnectfromasyncmy.replicationimportBinLogStreamimportasyncioasyncdefrun():conn=awaitconnect()ctl_conn=awaitconnect()stream=BinLogStream(conn,ctl_conn,1,master_log_file="binlog.000172",master_log_position=2235312,resume_stream=True,blocking=True,)asyncforeventinstream:print(event)if__name__=='__main__':asyncio.run(run())ThanksToasyncmy 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.LicenseThis project is licensed under theApache-2.0License.