High-performance MySQL driver for Python
Project description
pyro-mysql
A high-performance MySQL driver for Python, backed by Rust.
Usage
1. Connection
mysql_url = f"mysql://{USER}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}"
# Directly connect
conn = await pyro_mysql.Conn.new(mysql_url)
# Acquire from a pool
pool = pyro_mysql.Pool(mysql_url)
conn = await pool.acquire()
# Sync API
pool = pyro_mysql.SyncPool(mysql_url)
conn = pyro_mysql.SyncConn(mysql_url) or pool.acquire()
2. Query Execution
Conn and Transaction provides the following methods.
SyncConn and SyncTransaction provides the sync versions.
async def exec(self, query: str, params: Params) -> list[Row]
async def exec_first(self, query: str, params: Params) -> Row | None
async def exec_drop(self, query: str, params: Params) -> None
async def exec_batch(self, query: str, params: Iterable[Params]) -> None
# Examples
rows = await conn.exec("SELECT * FROM my_table WHERE a=? AND b=?", (a, b))
rows = await conn.exec("SELECT * FROM my_table WHERE a=:x AND b=:y AND c=:y", {'x': 100, 'y': 200})
await conn.exec_batch("SELECT * FROM my_table WHERE a=? AND b=?", [(a1, b1), (a2, b2)])
For exact description of each API, refer to the Rust doc.
3. Transaction
# async API
async with conn.start_transaction() as tx:
await tx.exec('INSERT ..')
await tx.exec('INSERT ..')
await tx.commit() # tx cannot be used anymore
# await conn.exec(..) # error: conn cannot be used while tx is active
# sync API
def func(tx: SyncTransaction):
tx.exec('INSERT ..')
tx.exec('INSERT ..')
tx.commit() # tx cannot be used anymore
conn.run_transaction(func)
DataType Mapping
Python -> MySQL
| Python Type | MySQL Binary Protocol Encoding |
|---|---|
None |
NULL |
bool |
Int64 |
int |
Int64 |
float |
Double(Float64) |
str | bytearray |
Bytes |
tuple | list | set | frozenset | dict |
json-encoded string as Bytes |
datetime.datetime |
Date(year, month, day, hour, minute, second, microsecond) |
datetime.date |
Date(year, month, day, 0, 0, 0, 0) |
datetime.time |
Time(false, 0, hour, minute, second, microsecond) |
datetime.timedelta |
Time(is_negative, days, hours, minutes, seconds, microseconds) |
time.struct_time |
Date(year, month, day, hour, minute, second, 0) |
decimal.Decimal |
Bytes |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyro_mysql-0.1.1.tar.gz
(625.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyro_mysql-0.1.1.tar.gz.
File metadata
- Download URL: pyro_mysql-0.1.1.tar.gz
- Upload date:
- Size: 625.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
461428b52b94861f2d1673713c4da16df681492584d051991ea5ec9e6df7b10a
|
|
| MD5 |
af086c943eafde460e5b3c853b828584
|
|
| BLAKE2b-256 |
f644dd112f50689052a95cd493a0b38d050c07567d937a16affe3e0e1a439142
|
File details
Details for the file pyro_mysql-0.1.1-cp314-cp314-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: pyro_mysql-0.1.1-cp314-cp314-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
955f6ee486e5ea56ce18caa6fae4e261773332cc5a69f78e7181bb83099aa2b5
|
|
| MD5 |
179f718c8e1d34fc72e2a94ba9c935f6
|
|
| BLAKE2b-256 |
57e4ce2e4791dc20b62fa5426b06c128131cc962c3e75697332f333cffc38658
|