Skip to main content

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 and Async 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlcycli-1.1.0.tar.gz (2.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sqlcycli-1.1.0-cp312-cp312-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.12Windows x86-64

sqlcycli-1.1.0-cp312-cp312-musllinux_1_1_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

sqlcycli-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

sqlcycli-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sqlcycli-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

sqlcycli-1.1.0-cp312-cp312-macosx_10_9_universal2.whl (5.4 MB view details)

Uploaded CPython 3.12macOS 10.9+ universal2 (ARM64, x86-64)

sqlcycli-1.1.0-cp311-cp311-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.11Windows x86-64

sqlcycli-1.1.0-cp311-cp311-musllinux_1_1_x86_64.whl (11.8 MB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

sqlcycli-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

sqlcycli-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

sqlcycli-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

sqlcycli-1.1.0-cp311-cp311-macosx_10_9_universal2.whl (5.4 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

sqlcycli-1.1.0-cp310-cp310-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10Windows x86-64

sqlcycli-1.1.0-cp310-cp310-musllinux_1_1_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

sqlcycli-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

sqlcycli-1.1.0-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

sqlcycli-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

sqlcycli-1.1.0-cp310-cp310-macosx_10_9_universal2.whl (5.4 MB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file sqlcycli-1.1.0.tar.gz.

File metadata

  • Download URL: sqlcycli-1.1.0.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for sqlcycli-1.1.0.tar.gz
Algorithm Hash digest
SHA256 be7f4c4846c95b92536b71167160b4178996047b5c8bad84b9d4fe1cc1dde92a
MD5 00b444e9fb9e7631f60073348b149a8d
BLAKE2b-256 803903f6ec9751f072d6ceec7055ec3d63610d26936c58cb6cb7b3dec16838cc

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: sqlcycli-1.1.0-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.5

File hashes

Hashes for sqlcycli-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3b082626a4997a8aa445f0dc2e8b6513fe1a5b14efbe1c527cd856e20a8c545d
MD5 922694593ded088b8015d15a33310872
BLAKE2b-256 af6a529beec76ba5b5db120c58176ccdd8a561d3f762774ccd3a53c676786c4f

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bcdb164e06d8673143ac44c41ebfae172633f7ff7d6bf49b19e083134ec803e8
MD5 19e89739a0440b592c93918c7663ca00
BLAKE2b-256 f37d00fbb1850826361b39caacc338858d9cb0d4bfcc3b7f7bc19ab9601b8184

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1577b55739249b26c5a80e571a33a4f8ceacdcfc7b186936c7f36a0329864ccb
MD5 92106ddc4c5170e7cf0da0e963a7108f
BLAKE2b-256 0d94305d84d6d897c120b2c57d6e8401de364a6b4f4974d0016beb19f9c38621

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d78a99ac10270ec51741de684476616686e3cffa00f6aa9170a8e0fa5d48f5f2
MD5 05ede4bb500c1a6874e83812dcae448a
BLAKE2b-256 f820cb50941f55f0db00a30fc9eb58d24f6acf0ab6b9c178c6fb0f2917012cbf

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a6f7dce5172ccd375ecec4f3c09a24a24ff143f34ddb0b517ee2c6e6dce4937a
MD5 f9a5120c124fe9789548f036f875c77e
BLAKE2b-256 7bb6ff1ad1bcada661169b074d76b1f44e55e57eb3eb7cb55179e1e1bd66c0b1

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 cc97aac0a091b2bdf497f0271fdad3741deac77967b62a7697930b9b5cd3a105
MD5 6685d3ac63edde28444cdfb1f08fd601
BLAKE2b-256 724de31a135d69e5cec8dd5a67fae99f07f308c3ec279cdf6940d6c21cec7edc

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: sqlcycli-1.1.0-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.5

File hashes

Hashes for sqlcycli-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d725f311dbcc20df782683e554df3df318d56491d19e8573a78a4d1a32491e9a
MD5 99dfa1ae6937ca17dabeab191488b764
BLAKE2b-256 160c558ceca6a8355da2526b941a2c34542b473dd341c05e4e56ece0b2fc81ca

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4afd80dfdc73179069666f131f5341ee3017293b252d7ca31bb56632e34e69ca
MD5 c4c99f4e8a293b6d2af99215d3593f57
BLAKE2b-256 b92ca555271477e5c6f94ff0873121f9fdfb6ba30b126ae1f519b3288b4c6916

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 494767f7400269250fa228f894ba7a9cf20be919aba9069984e53a58056dbcd7
MD5 bfb8d5ca5ff241b79648f62bf8300629
BLAKE2b-256 76b89a813e915207c30918e4c05c297ae6ad6f4cd41153b322144835245c6211

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 652b1952e0b3bc5d257070e147395ba74786f7c8a0f7666e2031fd888297bdfb
MD5 6115516b9943828d53ea1f82302c864a
BLAKE2b-256 cc6c3239417db8cf7cb2a39459b65b8b6a8730703bc1cd5a3143d4f4b6fd0d2d

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e92db07a3a4959dc85c0ddc77a330d58c89198ffce5c2e62c2b6f7cbe8a18046
MD5 e1f4b79195540c93bc23c03fc5127380
BLAKE2b-256 64af44743d8f21f528dd13b40a1daf93c7415fde44d42193c48e127d96fa620a

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 587120f0c3030fd2455fb705a6b20a5afcca92a8d0bfa9aaa619da2606d93be4
MD5 0c60faddf504894efab2624676bf8e1c
BLAKE2b-256 5ab8979647f49f89250d3ca316985e865da266283326bcca5de8f0500b3b4fe4

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: sqlcycli-1.1.0-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.5

File hashes

Hashes for sqlcycli-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3e31d4b92f064fd17e8aefa220551e31cbc04195c94b9db9750eb729c1f1e362
MD5 7cf2ff7e55a57004dfe00fffa2595742
BLAKE2b-256 e917656185db74e4ec9fa465cd37e48539b600a39cd1ee2d5f2ca0efe4160fc5

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 b098356262b9f7838a708ce244ba30f8ce3a23b8f04c7bfa56bf75d7b6af339b
MD5 bf924f9711eb1249a0a8bbfe87950538
BLAKE2b-256 074f52e17140944382c538a575ad37b3bc30ba0025788502aa81ae1e20758f25

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ae6352c5530a56d2b94ca0cc818a5f67104cd559bd4926f61b2204986d01986
MD5 e564a4f4b10986fd61eeb31dd79822bc
BLAKE2b-256 68402bce006dfab341a63c5f3a263d6359b3dbb976a85fc87a3d0242c0130504

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef6cd9b323d277e9d74687bb564df39cf09ef13c66d6871ced29c4fdb9181041
MD5 153a9865637102fab3030df1fc204fb0
BLAKE2b-256 8011c4952a0cc3d9e9ee6ac2202921050bfc861edf3f0596d268da8646e0185e

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ddd0b376f0ca06b1a467b823c41b98b229d8b4e4ed48a1aa5d921fabe038d77b
MD5 6da08415acc18059b58908cbe07d9e0f
BLAKE2b-256 302d2aa7d398920303bd9d1891f47142bd01c5c2f79b4f58eb9cc99e2a8fec92

See more details on using hashes here.

File details

Details for the file sqlcycli-1.1.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sqlcycli-1.1.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c20a0007b1e7b5fd266dd87949592c41f5a2caefb0da00be931477ce05e801e4
MD5 9b76c4a478230adb14912fe61cfd9b26
BLAKE2b-256 6ed28ce9fc4a973e8dfb15d86a74f1cfc46d300d57bc1bf3dc478bf4f6833247

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page