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
Sync
andAsync
connection 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
NOT
support 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())
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
File details
Details for the file sqlcycli-1.1.3.tar.gz
.
File metadata
- Download URL: sqlcycli-1.1.3.tar.gz
- Upload date:
- Size: 2.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e67b7d7dc3c028bdbbab496b64a446974646cd535f81cc22057d9cc5a3af021 |
|
MD5 | 8605d1382a2995579755a41b49a448a5 |
|
BLAKE2b-256 | 8e5dd0611d14013c64ee12ec423b97031edba8c6a6fbdd241d00abc8885e4f7e |
File details
Details for the file sqlcycli-1.1.3-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 182c31909382804ab57954d2710a517e41bfcea8ce2b17439085f65605fbd70d |
|
MD5 | aaabd746f5c5cd276ecaf1b90d5e012e |
|
BLAKE2b-256 | 76f05d85b062c1ceca746be2bc245e621faf1f8c6ace21a0c32f0a4353a32903 |
File details
Details for the file sqlcycli-1.1.3-cp312-cp312-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp312-cp312-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.7 MB
- Tags: CPython 3.12, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3181f55456b200d390f8a5dea280bcd9fbb16d1fa600216eb972c29fe64d9802 |
|
MD5 | ac93d8e027405fd5f7b04bf1f6573990 |
|
BLAKE2b-256 | 3f0d772b92f929a2e6e745ffad21c0145a709e25dab99b332548f79b6b7d3809 |
File details
Details for the file sqlcycli-1.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.7 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 551f20c4fc8c30d10717f9a6321cfa36f7c663828633c5c6f3a772333b261948 |
|
MD5 | c89f5144a49e692e8162d39317e099c0 |
|
BLAKE2b-256 | d55acd0e00166652a29c66f70d7063ab56aa0110a7b26fe7576ffd2818a66f87 |
File details
Details for the file sqlcycli-1.1.3-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb65fe88bdbc4659cbbc12d9f91ceb5868bc1472456a2f289f28205b05a3f928 |
|
MD5 | aec9033aca5973b22eedd126a6c1c391 |
|
BLAKE2b-256 | 205528f779cea8583affd047c1b6acd17283f8affe4e9740b875d15b8b7618d9 |
File details
Details for the file sqlcycli-1.1.3-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c5de48634b8fe69c3d5dee6f63cf03e58ea0e1629fcd2d78a6ccae84a9a1053 |
|
MD5 | af5ade6ccd0a47d464c6deea9d06ef66 |
|
BLAKE2b-256 | 38e4e055678a7f1d606ba5626fc51eeb111ff2e61f8a0a050ce1f75de9e38b8e |
File details
Details for the file sqlcycli-1.1.3-cp312-cp312-macosx_10_9_universal2.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp312-cp312-macosx_10_9_universal2.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.12, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ca4dadcdc0d3daed382fe22eb05221b5b1a7f364e0484e07ff9c035457b44b7 |
|
MD5 | 6ebb8f950503a701517b3d9e6ccd58ca |
|
BLAKE2b-256 | f75f21c2c9f30604f44e9f955dd3bfcd9a8743de9115f9ffa6091afe8a262fef |
File details
Details for the file sqlcycli-1.1.3-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2244a5ac7ae4eb9581eb6975a5290183ac185d709751a325508d42fa23dea4de |
|
MD5 | 3835a54e73e9b4c10fd5b38477d161f9 |
|
BLAKE2b-256 | 730e5ed34914d8c2bd67441d97f91de477b64d81704fece2c00d4d92ae05e54e |
File details
Details for the file sqlcycli-1.1.3-cp311-cp311-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp311-cp311-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.8 MB
- Tags: CPython 3.11, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2386c6f6d6f63d2152c9e809272eeddf5508b54608ce5bbf54d06e72f1d0aca4 |
|
MD5 | 95458afcd1d5869a689fe2f28567570f |
|
BLAKE2b-256 | d19b1df318534ce393d5ba26a03d58b34904b60689c3aea2f958ecd563ac8ef9 |
File details
Details for the file sqlcycli-1.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.7 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 310470e6b34d4180c31a62f14d9421b58e0551a817a758931eca0168e6d09c6c |
|
MD5 | 61d06c52e54e06e160cba1ff42d16683 |
|
BLAKE2b-256 | 4ffc70461c934f8f8f9eb88de5db4faa35c137a2fe7c39ccf3c3bcaf3f5d73a2 |
File details
Details for the file sqlcycli-1.1.3-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3293bb598621146d8cf01f0ef02b858a48ecced70d51936fc4ac6e72879ecb4a |
|
MD5 | 5d040921938d4015e20bd7e78a9ff154 |
|
BLAKE2b-256 | 327934a2fec749f25f53674c1d0055b88e8169b1b08735cceeab2735689d6b26 |
File details
Details for the file sqlcycli-1.1.3-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7503cfaa6afbe7d6f9aa37acaee533e40516b08576281c6e17d1b33551759685 |
|
MD5 | f100e429cc102c94cf780a1c0b72fb8a |
|
BLAKE2b-256 | f9f3f8b4d7f7acb6b63e11026232f4d9d039eba3c3c8570113588935ffe19abf |
File details
Details for the file sqlcycli-1.1.3-cp311-cp311-macosx_10_9_universal2.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a89ca7374736723a57bda3f9e457dfd8062a76843fbd4dc0b7d30bf9fce8e8d3 |
|
MD5 | a74fc9a48ba4a7c427135ece0d3bbd12 |
|
BLAKE2b-256 | 24dfce64defef05085b30f17e6ea056155e72d258547529086f3449bdcaca557 |
File details
Details for the file sqlcycli-1.1.3-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa5b3bb0f57244e5d2f3d6d1d78458c990cc31dd50123448ebd345ccd0564e9d |
|
MD5 | 8bf422c30a9346a9fe3d512db5738cfd |
|
BLAKE2b-256 | 291bf1471aa310983d9552dcdd6c3bf0f7303c8dd3d9f6a51801be3055bfc609 |
File details
Details for the file sqlcycli-1.1.3-cp310-cp310-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.0 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63b1fde964b80b12ff0d4f84a0d82791909b0b6449d160bf07f0cca74de86366 |
|
MD5 | 30b0395af35a324499aeb61824f4acc4 |
|
BLAKE2b-256 | 2d21c3298ff820263234fca538917d27216374b1f17956149dea32508a0de086 |
File details
Details for the file sqlcycli-1.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cd2a58899b815a338faf867cdcd1f177cb603033ec4a67bc1334d51795760b3 |
|
MD5 | 27139bc9d5f3800ea3578db5dcec7f07 |
|
BLAKE2b-256 | 22c2487b986e0045b059912d64243cb4daaa89853b7b0b69d6f3be1c6ba22310 |
File details
Details for the file sqlcycli-1.1.3-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee98fd27d083b04f9bcaf8d535613da742a6f85ea12647401e5e8812ed477318 |
|
MD5 | 7498f6536f49b7e2b9df2261b6301910 |
|
BLAKE2b-256 | 40e0c27de4c74166227fff6937735b496212cdb74a3cf66e3fe8b2f6c21cd8e2 |
File details
Details for the file sqlcycli-1.1.3-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8df63dc1fc39060b7e27721a47ac1541226c1ddfcfb3245885ecf66bfec4dff |
|
MD5 | 837757f53f2253176038b74bc6370b4d |
|
BLAKE2b-256 | bf90dd08f54644baaa29119fc6da4d5d16d1d5bd3d29c0c09c2634e2ad641110 |
File details
Details for the file sqlcycli-1.1.3-cp310-cp310-macosx_10_9_universal2.whl
.
File metadata
- Download URL: sqlcycli-1.1.3-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aba6f36ada48024f33ec0f9e5d38240ec3a1072de4e324abd3e513b78d3cc01 |
|
MD5 | dd9da201c99f29fc0c45f6a76feb03c0 |
|
BLAKE2b-256 | 12a99154ff4e8528873a68dc5eb3088080c097a734f8e2d94c8b63566761cbda |