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
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
- 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
SQLCyCli sync 50000 2.314604 0.352408 2.303785 0.045072
PyMySQL sync 50000 2.564615 0.453932 5.005772 0.321882
SQLCyCli async 50000 3.470987 0.349488 4.227539 0.112310
aiomysql async 50000 3.655537 0.435786 5.882189 0.337962
asyncmy async 50000 3.694391 0.414223 5.372794 0.278912
# Unit: second | Lower is better
name type rows update-per-row update-all delete-per-row delete-all
SQLCyCli sync 50000 2.438695 0.463743 2.239835 0.129764
PyMySQL sync 50000 2.728665 0.352855 2.415529 0.128943
SQLCyCli async 50000 3.591613 0.536130 3.452353 0.134043
aiomysql async 50000 3.678571 0.352699 3.567383 0.134994
asyncmy async 50000 3.852939 0.321264 3.615992 0.134843
Usage
Use connect() to create a connection (Sync or Async) with the server.
import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Connection (Sync & Async)
async def test_connection() -> None:
# Sync Connection - - - - - - - - - - - - - - - - - -
with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Connection closed
assert conn.closed()
# Async Connection - - - - - - - - - - - - - - - - -
async with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# Connection closed
assert conn.closed()
if __name__ == "__main__":
asyncio.run(test_connection())
Use create_pool() to create a Pool for managing and maintaining connections (Sync or Async) with the server.
import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Pool (Context: 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
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# Pool closed
assert pool.closed() and pool.total == 0
# Pool (Context: 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
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# 1 free async connection
assert pool.free == 1
# Pool closed
assert pool.closed() and pool.total == 0
if __name__ == "__main__":
asyncio.run(test_pool_context_connected())
asyncio.run(test_pool_context_disconnected())
Use the Pool class to create a Pool instance. Must close manually.
import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Pool (Instance: Connected)
async def test_pool_instance_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
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# Close pool manually
await pool.close()
assert pool.closed() and pool.total == 0
# Pool (Instance: Disconnected)
async def test_pool_instance_disconnected() -> None:
pool = sqlcycli.Pool(HOST, PORT, USER, PSWD, min_size=1)
# Pool is not connected: 0 free connection (min_size=1)
assert pool.closed() and pool.free == 0
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# 1 free async connection
assert pool.free == 1
# Close pool manually
await pool.close()
assert pool.closed() and pool.total == 0
if __name__ == "__main__":
asyncio.run(test_pool_instance_connected())
asyncio.run(test_pool_instance_disconnected())
Use the sqlfunc module to escape values for MySQL functions.
import asyncio
import datetime
import sqlcycli
from sqlcycli import sqlfunc
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "Password_123456"
# SQLFunction
def test_sqlfunction() -> None:
with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
with conn.cursor() as cur:
cur.execute("SELECT %s", sqlfunc.TO_DAYS(datetime.date(2007, 10, 7)))
# SQLFunction 'TO_DAYS()' escaped as: TO_DAYS('2007-10-07')
assert cur.executed_sql == "SELECT TO_DAYS('2007-10-07')"
assert cur.fetchone() == (733321,)
# Connection closed
assert conn.closed()
if __name__ == "__main__":
test_sqlfunction()
Acknowledgements
SQLCyCli is build on top of the following open-source repositories:
SQLCyCli is based on the following open-source repositories:
Metadata
Release files for sqlcycli 2.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlcycli-2.3.1.tar.gz | 3.9 MB | Without provenance | Details for sqlcycli-2.3.1.tar.gz |
Built distributions (wheels)
Total release size: 220.5 MB
Release files / sqlcycli-2.3.1.tar.gz
| Download URL | sqlcycli-2.3.1.tar.gz |
|---|---|
| Size | 3.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
542a78fad58b607ca76b7c44029e18e26b51708da933d0cdd08b5945f4a717ba
|
|
BLAKE2b-256 checksum How to use checksums |
6be261d6a65de60f06b3d7e817f4a98bb5f3916cde7bf89aad9c70a2b6f711a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp313-cp313-win_amd64.whl
| Download URL | sqlcycli-2.3.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9caa8a495bace229f75e02ddb75ff2f0c27e0bbed887249dd030cb259f0dc487
|
|
BLAKE2b-256 checksum How to use checksums |
2d459d3fa411bd75f07ade42c7cad215fc5cc36c03c12b61e776160680684d67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 19.2 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
eaeba58759ef1fc5d6f4a5db63d19325e84a59ffaf924af0dc91296dd6cfe55a
|
|
BLAKE2b-256 checksum How to use checksums |
1b350ba8998547c9c707cc5c2606c2692d0f509b65e511666e3d103b17851c0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 20.7 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
78c566671352845b481cfb7e18c6d19202f9c22ef1e37e194fe2677548f313b0
|
|
BLAKE2b-256 checksum How to use checksums |
71bd9e1f22bb5513c40879e72e3a9e9ea55ba079d16425c3d9c6ccbe08f86896
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp313-cp313-macosx_10_13_universal2.whl
| Download URL | sqlcycli-2.3.1-cp313-cp313-macosx_10_13_universal2.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
1578bb2577c75500b34119debf0525b3bee37e281eb425a64990f1ab7993cd50
|
|
BLAKE2b-256 checksum How to use checksums |
4eff9e8b1ad27609ab6c0c6416cd646080ce693a437d695035166f9742d225b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp312-cp312-win_amd64.whl
| Download URL | sqlcycli-2.3.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8eef79fd01fc453dd3990622309f1c2809edd26e703f287bd231312cea37a2eb
|
|
BLAKE2b-256 checksum How to use checksums |
36506c7172213c28594fad8e917fed8a0aad24d204a4572e322938f1ff2bc01d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 19.3 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
2e8a1ccf2bf7e7469da607b67688c273cfaf2fa8b33fe1683dca5f460eda319e
|
|
BLAKE2b-256 checksum How to use checksums |
aeebb096c4c1aafc9c616a0450e64fceee49c68ae8f77a223bf3f68acb356531
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 20.8 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ee2d36d45b56061366cda87d679443ee9689dc97fe1c33e01a402840d5811b3e
|
|
BLAKE2b-256 checksum How to use checksums |
c5fb1144974a20bf92defc65c4f5a27b3d44401dde8051f1a54ad9ad565992c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp312-cp312-macosx_10_13_universal2.whl
| Download URL | sqlcycli-2.3.1-cp312-cp312-macosx_10_13_universal2.whl |
|---|---|
| Size | 8.6 MB |
| Tags | CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
ec4f33ac7c46792db0088e0395040886d1c5945b398ce9b19adbe5795f472411
|
|
BLAKE2b-256 checksum How to use checksums |
d3cec68f0b974df41af6c32f96aa6f80e37ff6f2b2b16777714ec27219beefb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp311-cp311-win_amd64.whl
| Download URL | sqlcycli-2.3.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5d8dca0194c1cbb60cf03bcbace61024322bf8cba6d6c7d6a299be13ff5a107c
|
|
BLAKE2b-256 checksum How to use checksums |
2d42bc804d058f48556d3acd327d58a8e7506eed165fa8cb75cb17134c8d6570
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 19.5 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
05a7ffeb748ce45e126eee28e2c1dd81b7c071a6f8211143850077b25089bab1
|
|
BLAKE2b-256 checksum How to use checksums |
4adc187a14b145f054feecd260eeccbb2c1faa39339bc732df08f157fb1060fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 21.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
f20d0cc6916524309929e6d0ae30968f12c00e2f766ac42c7a2ea705247f1069
|
|
BLAKE2b-256 checksum How to use checksums |
a684ad3db01a9a5d98eea28a20e95f358db83499ef0c0568056fb7138956bdd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp311-cp311-macosx_10_9_universal2.whl
| Download URL | sqlcycli-2.3.1-cp311-cp311-macosx_10_9_universal2.whl |
|---|---|
| Size | 8.6 MB |
| Tags | CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
e921b9eafeb8594219f5f09d7f0b94ab866eecd7d471a3ea3fd4b3ba028e063f
|
|
BLAKE2b-256 checksum How to use checksums |
85dfc02441665e8c9068a1aea49557ca40051f754b59ecc60066b30bfb860d5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp310-cp310-win_amd64.whl
| Download URL | sqlcycli-2.3.1-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
50c8bdfe989a2c20a822047ade11b78b3cc65b5d02301ae23c1fd4fd97df24fe
|
|
BLAKE2b-256 checksum How to use checksums |
67e57a1851db0901441b8467dceff3d604132b1f5a1d37441448a6ba1c7c37da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 18.2 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
8b4eee330365163b947ca8b9e76711531eca0bb58414a1c850183f4100a6a0e2
|
|
BLAKE2b-256 checksum How to use checksums |
361e4baa7dd5ade2c1f85bbbef5b3e16e5351c9227811dd1498d15339d1e206c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | sqlcycli-2.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 19.7 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
3571439f87374f53b219a33eabb1cfe07da7cf7cc0eeede21941cfa190a46b51
|
|
BLAKE2b-256 checksum How to use checksums |
9bfcb9893e26df8d4277676496fae11bec0d8e70acd18760de784c09903ce158
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / sqlcycli-2.3.1-cp310-cp310-macosx_10_9_universal2.whl
| Download URL | sqlcycli-2.3.1-cp310-cp310-macosx_10_9_universal2.whl |
|---|---|
| Size | 8.6 MB |
| Tags | CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
7add4bb1ce2a13ddcc8237665e45c1675001a3a321f336f75faafdf6945f75ec
|
|
BLAKE2b-256 checksum How to use checksums |
4520f8db49d1668b551bb4b97d8fcb1462edd29edac0258e35e7b7b3818193c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for sqlcycli 2.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.