rustmy¶
A fast MySQL and MariaDB driver for Python, written in Rust. DB-API 2.0 and asyncio, connection pools, SQLAlchemy and Django, and wheels with nothing else to install.
pip install rustmyexecutemanyWrite it the way you already do¶
import rustmy
with rustmy.connect(
host="localhost", user="app", password="secret", database="shop"
) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT id, name, price FROM products WHERE price < %s", (10,))
for product_id, name, price in cursor:
print(product_id, name, price)
conn.commit()
import asyncio
from rustmy import aio
async def main() -> None:
async with aio.create_pool(
host="localhost", user="app", password="secret", database="shop"
) as pool:
async with pool.acquire() as conn, conn.cursor() as cursor:
await cursor.execute(
"SELECT id, name FROM products WHERE price < %s", (10,)
)
for product_id, name in await cursor.fetchall():
print(product_id, name)
asyncio.run(main())
from sqlalchemy import create_engine, text
engine = create_engine("mysql+rustmy://app:secret@localhost/shop", pool_pre_ping=True)
with engine.connect() as conn:
rows = conn.execute(text("SELECT id, name FROM products")).all()
On asyncio, create_async_engine("mysql+rustmy://app:secret@localhost/shop").
Why rustmy¶
-
Fast where it counts
Rows are read in small batches with the GIL released and converted in Rust while the server sends the next batch.
executemanybatches inserts and pipelines everything else. -
Nothing to install but the wheel
No libmysqlclient, no compiler, no
pkg-config. TLS is rustls, and the supported authentication methods are implemented in Rust. -
asyncio on the same core
rustmy.aioruns the same Rust protocol code on the event loop's thread, with the API of aiomysql and asyncmy. No thread per query. -
Pools for threads and tasks
rustmy.Poolandrustmy.aio.create_poolserve waiters in order of arrival, ping idle connections and roll back what is given back open. -
SQLAlchemy and Django
mysql+rustmy://andmariadb+rustmy://, blocking and asyncio, and Django's MySQL backend throughinstall_as_MySQLdb(). -
Correct and tested hard
The server's definition of every character set, property-based tests of escaping and injection, fuzzing, and nine server versions in CI.
Supported¶
| Supported | |
|---|---|
| Python | CPython 3.10 to 3.15, free-threaded 3.14t and 3.15t |
| MySQL | 8.0, 8.4 LTS, 9.7, 26.x |
| MariaDB | 10.11, 11.4, 11.8, 12.3, 13.x |
| Frameworks | SQLAlchemy 2.0 and 2.1 (blocking and asyncio), Django 5.2 LTS and 6.x |
| Platforms | Linux x86_64 and aarch64 (glibc, musl), macOS x86_64 and arm64, Windows x64 and arm64 |