Fast MySQL driver build in Cython (Sync and Async).
Project description
Fast MySQL driver build in Cython (Sync and Async).
Created to be used in a project, this package is published to github for ease of management and installation across different modules.
Installation
Install from PyPi
pip install sqlcycli
Install from github
pip install git+https://github.com/AresJef/SQLCyCli.git
For Linux systems, if you encounter the following error when installing the SQLCyCli dependency mysqlclient:
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
Try the following to fix dependency issue (source: Stack Overflow):
sudo apt-get install pkg-config python3-dev default-libmysqlclient-dev build-essential
Requirements
- Python 3.10 or higher.
- MySQL 5.5 or higher.
Features
- Written in Cython for optimal performance (especially for SELECT/INSERT query).
- All classes and methods are well documented and type annotated.
- Supports both
SyncandAsyncconnection to the server. - API Compatiable with PyMySQL and aiomysql.
- Support conversion (escape) for most of the native python types, and objects from libaray numpy and pandas. Does
NOTsupport custom conversion (escape).
Benchmark
The following result comes from benchmark:
- Device: MacbookPro M1Pro(2E8P) 32GB
- Python: 3.12.4
- MySQL: 8.3.0
- mysqlclient: 2.2.4
- PyMySQL: 1.1.1
- aiomysql: 0.2.0
- asyncmy: 0.2.9
# Unit: second | Lower is better
name type rows insert-per-row insert-bulk select-per-row select-all
mysqlclient sync 50000 1.729575 0.435661 1.719481 0.117943
SQLCyCli sync 50000 2.165910 0.275736 2.215093 0.056679
PyMySQL sync 50000 2.553401 0.404618 4.212548 0.325706
SQLCyCli async 50000 3.347850 0.282364 4.153874 0.135656
aiomysql async 50000 3.478428 0.394711 5.101733 0.321200
asyncmy async 50000 3.665675 0.397671 5.483239 0.313418
# Unit: second | Lower is better
name type rows update-per-row update-all delete-per-row delete-all
mysqlclient sync 50000 1.735787 0.345561 1.531275 0.105109
SQLCyCli sync 50000 2.241458 0.343359 2.078324 0.104441
PyMySQL sync 50000 2.516349 0.344614 2.264735 0.104326
SQLCyCli async 50000 3.465996 0.343864 3.269337 0.103967
aiomysql async 50000 3.534125 0.344573 3.345815 0.104281
asyncmy async 50000 3.695764 0.352104 3.460674 0.104523
Usage
Use connect() to create one connection (Sync or Async) to the server.
import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Synchronous Connection
def test_sync_connection() -> None:
with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
res = cur.fetchone()
assert res == (1,)
# Connection closed
assert conn.closed()
# Asynchronous Connection
async def test_async_connection() -> None:
async with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
res = await cur.fetchone()
assert res == (1,)
# Connection closed
assert conn.closed()
if __name__ == "__main__":
test_sync_connection()
asyncio.run(test_async_connection())
Use create_pool() to create a Pool for managing and maintaining Async connections to the server.
import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Pool (Context Manager: Connected)
async def test_pool_context_connected() -> None:
async with sqlcycli.create_pool(HOST, PORT, USER, PSWD, min_size=1) as pool:
# Pool is connected: 1 free connection (min_size=1)
assert not pool.closed() and pool.free == 1
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
res = await cur.fetchone()
assert res == (1,)
# Pool closed
assert pool.closed() and pool.total == 0
# Pool (Context Manager: Disconnected)
async def test_pool_context_disconnected() -> None:
with sqlcycli.create_pool(HOST, PORT, USER, PSWD, min_size=1) as pool:
# Pool is not connected: 0 free connection (min_size=1)
assert pool.closed() and pool.free == 0
# Connect automatically
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
res = await cur.fetchone()
assert res == (1,)
# 1 free connection
assert pool.free == 1
# Pool closed
assert pool.closed() and pool.total == 0
# Pool (Create Directly: Connected)
async def test_pool_direct_connected() -> None:
pool = await sqlcycli.create_pool(HOST, PORT, USER, PSWD, min_size=1)
# Pool is connected: 1 free connection (min_size=1)
assert not pool.closed() and pool.free == 1
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
res = await cur.fetchone()
assert res == (1,)
# Close pool manually
await pool.close()
assert pool.closed() and pool.total == 0
if __name__ == "__main__":
asyncio.run(test_pool_context_connected())
asyncio.run(test_pool_context_disconnected())
asyncio.run(test_pool_direct_connected())
Use sqlfunc module to escape MySQL function values.
import datetime
from sqlcycli import Connection, sqlfunc
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "Password_123456"
conn = Connection(host=HOST, port=PORT, user=USER, password=PSWD)
conn.connect()
with conn.cursor() as cur:
cur.execute("SELECT %s", sqlfunc.TO_DAYS(datetime.date(2007, 10, 7)))
res = cur.fetchone()
print(cur.executed_sql)
# "SELECT TO_DAYS('2007-10-07')"
print(res)
# (733321,)
conn.close()
Acknowledgements
SQLCyCli is build on top of the following open-source repositories:
SQLCyCli is based on the following open-source repositories:
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
Built Distributions
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 sqlcycli-1.2.1.tar.gz.
File metadata
- Download URL: sqlcycli-1.2.1.tar.gz
- Upload date:
- Size: 3.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27b37ff9f7ce3c470c8daf076890292b2cf15b89a173c6f822fe34dbeebfd157
|
|
| MD5 |
8ea58908dd396191ad10dabc7670ed47
|
|
| BLAKE2b-256 |
b2dcdc9922dbedf30578cddfed547d3437746a75cab94cf0d796beb6641426c2
|
File details
Details for the file sqlcycli-1.2.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2c78d7aa548ec493aae467b22342332818f7b06e306d0c46f33580a8993ac86
|
|
| MD5 |
e2df20f1cb256c13d1219e1ca50da782
|
|
| BLAKE2b-256 |
2ac3a717fd82cd4198adaf1f0df962fe48ccc53edf827fd886a7d3372b1168ef
|
File details
Details for the file sqlcycli-1.2.1-cp312-cp312-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp312-cp312-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 22.0 MB
- Tags: CPython 3.12, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0864ed3a9fe39d80cd127f5d201ebd04df17069fece6fb334a9b56b9ab67559
|
|
| MD5 |
f8a3928464487d4c9ff3a4676f457d85
|
|
| BLAKE2b-256 |
4dbc900c34e3eb4f7b5645ceb3d4fd04588a1a94136454071f580eb72f4f94e4
|
File details
Details for the file sqlcycli-1.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 22.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b84d36d2cd55ca79a03e380d13b7df654797e0aee69b3bd4e8b8289d970ebd64
|
|
| MD5 |
bc7d3c96b7d6d33fd54dcc1621117867
|
|
| BLAKE2b-256 |
fbf9914105c8245397fcbf23b89b5a6c52bb8b0c4dc3d06760bf89bd2085a16d
|
File details
Details for the file sqlcycli-1.2.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.9 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b0918817ab7ab0c1b2b6c8deaa8567112ef55e8c2d650f11fba66f155b3e7a0
|
|
| MD5 |
37a06a4155107899f8ba1c157485c492
|
|
| BLAKE2b-256 |
e716eeffe8cdc434374bc12c4d92a92407cf3f1ef1a4c3ddaee9726ab4c544c6
|
File details
Details for the file sqlcycli-1.2.1-cp312-cp312-macosx_10_9_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec35d70d03cc5b927c501acbf88b5dc803b7e2134c8361190aa0b9086953eac5
|
|
| MD5 |
6958d832ec8f98c046055154ba368a4b
|
|
| BLAKE2b-256 |
34b073c30b40f07440d03bbe9946c95e11058e7beefd1e505625148335109712
|
File details
Details for the file sqlcycli-1.2.1-cp312-cp312-macosx_10_9_universal2.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp312-cp312-macosx_10_9_universal2.whl
- Upload date:
- Size: 8.5 MB
- Tags: CPython 3.12, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad3e9c6081e20d99fb02ee9c9ceeabcc1d7b5aab482d4d880cb0f14b70669dac
|
|
| MD5 |
ac8e60499ee6e4f766e6ac3fe122b4e9
|
|
| BLAKE2b-256 |
af52dda4cc76ff446b0011094537bb6f366550c3b9ba1af9bca11953d4d237ae
|
File details
Details for the file sqlcycli-1.2.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fca79e6e14f8e60e23321925729dc98ad0338844991f3a5c14515dff32c463e8
|
|
| MD5 |
40f0af970d0816cc02f3b001055b6d04
|
|
| BLAKE2b-256 |
d918a85d38ba51c5511c54ee6e80ffeb77258127787aa6a0211a9e7dd4c281cc
|
File details
Details for the file sqlcycli-1.2.1-cp311-cp311-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp311-cp311-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 22.2 MB
- Tags: CPython 3.11, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d17f9550c677562545f2867d17b9bbd3512a2d24d7b859b0017b978af04f4cb7
|
|
| MD5 |
91d44db9e6c790366f1506fafd1f04b7
|
|
| BLAKE2b-256 |
bfce6ddba0ffcb5f84e4ad13464a822f71d5d18eac1f6ceea5a1b6f744049a98
|
File details
Details for the file sqlcycli-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 22.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43cb51fda5708ec605cc5bc5f598199203cc6d98c7426ce23263467d2a111d8a
|
|
| MD5 |
d49ba2e16636bd8e494c0e3c7d5932a6
|
|
| BLAKE2b-256 |
c1dd073b7994144ed3a19c608c215e97cb98dfcef24b6db6c71aae7ea5265ace
|
File details
Details for the file sqlcycli-1.2.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.9 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c96acbf29128909ea19f03fa7ee07b9235b8159374e61f793df5acd2b9c0fa39
|
|
| MD5 |
9a49cdb815d57a8704ee91bf39b55b30
|
|
| BLAKE2b-256 |
1d488524a18c91ffe59af59b1933504e18b1b19e4f3ffc5d47ec0542702fdd45
|
File details
Details for the file sqlcycli-1.2.1-cp311-cp311-macosx_10_9_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a7329883938871f852b9c83235d58f02deec8942e18094ac683ccecdb79cc2
|
|
| MD5 |
59e0805cee7d34e3eb05e46734b97215
|
|
| BLAKE2b-256 |
00434603b4b2c8f57b168a9a2491169f5895298d6db1727ea5e7f3dc600dd6ca
|
File details
Details for the file sqlcycli-1.2.1-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 8.5 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bcb27790e9d015045bb930a2691d1d069ae9d397a4aa40617f4b2fa456fa494
|
|
| MD5 |
5ef399d684be05d8dfc857f05d02f55e
|
|
| BLAKE2b-256 |
9cdcdf0ffb521bb8b4843454d5315998c39291dbc54ff11fbe99311330f31155
|
File details
Details for the file sqlcycli-1.2.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8feae9890120b1af8ad5305cdc9bb6ef583554494c7ac3866933553666d3626
|
|
| MD5 |
154abe74125be3b4cbfa729506ff0980
|
|
| BLAKE2b-256 |
8c8fbbfa2d2d6f6139e02fa9fc6d8527b8773e29eaf9f2760d92194c3f071f5b
|
File details
Details for the file sqlcycli-1.2.1-cp310-cp310-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 20.3 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3064f5ab71cffe26ffd214d3142e066956d36e8c27b74163d1d7016b42ac852
|
|
| MD5 |
23c70be30135cf5f7da4c88d269516a7
|
|
| BLAKE2b-256 |
246bd48ecfcc817e015d26cf12f6164ffaf30dd18990b6ab71704725ea320421
|
File details
Details for the file sqlcycli-1.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 20.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd867537d9734a4bd2a2b83ca384c4101c4de0bf9caca4b98c783d895493e72
|
|
| MD5 |
753a01b34f8e264e53be53efd0a66ccb
|
|
| BLAKE2b-256 |
9afa862ec050f5976b8bc767d0dcd1cb2967861873d1376fbf18ece66e5ea5c2
|
File details
Details for the file sqlcycli-1.2.1-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.9 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddbf2947ffbef6a969e72cc872ce5b0271c8eb77442ff99cd67d1f6ee340ef87
|
|
| MD5 |
2753da03529c552d22c75cb1c411fcb1
|
|
| BLAKE2b-256 |
f5bd4b8bf9aea613a51268fed65b97fbbb2b879ebb59a5cc2e90a1cf61e578bf
|
File details
Details for the file sqlcycli-1.2.1-cp310-cp310-macosx_10_9_x86_64.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf507825792224d0a38cbbc4c15095130c58c4485e463f4d09d759a358934142
|
|
| MD5 |
e12bee08b6ff370eedecf35c8a110102
|
|
| BLAKE2b-256 |
8c07a13fd3e83ad29e1c90f3487f136125cfa70241aa573e7b9c2b538a92166b
|
File details
Details for the file sqlcycli-1.2.1-cp310-cp310-macosx_10_9_universal2.whl.
File metadata
- Download URL: sqlcycli-1.2.1-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f38b34e5ab09970f90ab806359f6e39604a931d55559fe1e6a1a6fb6bf27633f
|
|
| MD5 |
dca6bdad5ec6519e6717c7948183c618
|
|
| BLAKE2b-256 |
02bdc3ccdf601aa4046dbf12fb613bff4b58ac09cfdbb0dd697816157d8c8671
|