Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
asyncmy
is a fast asyncio MySQL/MariaDB driver, which reuse most of pymysql
and aiomysql but rewrite core protocol with cython to
speedup.
asyncio
.The result comes from benchmark.
The device is iMac Pro(2017) i9 3.6GHz 48G and MySQL version is 8.0.26.
mysqlclient
is the fastest MySQL driver.select
.asyncio
could enhance insert
.asyncmy
performs remarkable when compared to other drivers.pip install asyncmy
To install asyncmy on Windows, you need to install the tools needed to build it.
vs_buildtools__XXXXXXXXX.XXXXXXXXXX.exe
, it will be easier if you rename
it to just vs_buildtools.exe
vs_buildtools.exe --norestart --passive --downloadThenInstall --includeRecommended --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools
pip install asyncmy
Now you can uninstall previously installed tools.
connect
asyncmy
provides a way to connect to MySQL database with simple factory function asyncmy.connect()
. Use this
function if you want just one connection to the database, consider connection pool for multiple connections.
import asyncio
import os
from asyncmy import connect
from asyncmy.cursors import DictCursor
async def run():
conn = await connect(user=os.getenv("DB_USER"), password=os.getenv("DB_PASSWORD", ""))
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
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
""".strip()
)
await conn.ensure_closed()
if __name__ == "__main__":
asyncio.run(run())
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,)
pool.close()
await pool.wait_closed()
if __name__ == '__main__':
asyncio.run(run())
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)
await conn.ensure_closed()
await ctl_conn.ensure_closed()
if __name__ == '__main__':
asyncio.run(run())
asyncmy is build on top of these awesome projects.
This project is licensed under the Apache-2.0 License.
FAQs
A fast asyncio MySQL driver
We found that asyncmy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.