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.5.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.5-cp312-cp312-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.12Windows x86-64

sqlcycli-1.1.5-cp312-cp312-musllinux_1_1_x86_64.whl (11.8 MB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

sqlcycli-1.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

sqlcycli-1.1.5-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sqlcycli-1.1.5-cp312-cp312-macosx_10_9_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

sqlcycli-1.1.5-cp312-cp312-macosx_10_9_universal2.whl (5.5 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

sqlcycli-1.1.5-cp311-cp311-musllinux_1_1_x86_64.whl (11.9 MB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

sqlcycli-1.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

sqlcycli-1.1.5-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

sqlcycli-1.1.5-cp311-cp311-macosx_10_9_universal2.whl (5.5 MB view details)

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

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

Uploaded CPython 3.10Windows x86-64

sqlcycli-1.1.5-cp310-cp310-musllinux_1_1_x86_64.whl (11.1 MB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

sqlcycli-1.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

sqlcycli-1.1.5-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

sqlcycli-1.1.5-cp310-cp310-macosx_10_9_universal2.whl (5.5 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for sqlcycli-1.1.5.tar.gz
Algorithm Hash digest
SHA256 073135245e66f8bcd0da5639d511c671da8bd62d9bd39b9674e4adb7152ffa8a
MD5 a1cced9bfa4803afa1278315a3e4c9f3
BLAKE2b-256 66ea9dfdb63a3d66f8c93ba7bf6d1cc1651cbf738e7e1c7b2cb509a7c3277729

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.9 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

Hashes for sqlcycli-1.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9e34dbdaa332a17b82fb0eb23baa017a325cfb9d9bdcb4e459bbd08573fed42a
MD5 60596010beb7f30f2bef243feacc109f
BLAKE2b-256 288edf7f68887b9cb334a004a0a1dca2edf39af044c2090938defd0699a7d380

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a5505838fdf12ac07d73427243787812007b801b4ea137d7bc50b9d23f558c4a
MD5 d1127202dec731d751d91d6059e6084d
BLAKE2b-256 aec6d8c457b809c31b1a626e4379537a111872707e372d2f0d8d23c01c4909f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d54f09eb31131302cf8370b07e83b5ff958cf204a62c162532c40d3616a4f0fe
MD5 d0d7260dc23579a7c8a0d276341a6bd2
BLAKE2b-256 f7a04d0b4afc18226c5983da478be3b196e2fa8faff374ae6fe4d64366c5ffc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e8eaba67f4d1ac15e72a1e6b7cbaf25a4ab919e93ee97d320396f25f6fcc956
MD5 8e14f8c886abd6b928c4c3762bf1f43e
BLAKE2b-256 7af81633868c302fcd0078981a6faf4db00c5f6f6ea642c75a4b8e994fba6340

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0e3cafbb6e2cf7446446ba836c349ea51420ab3be650f8365e524dd0454eee5d
MD5 d88d0477e8b459339b6039e74744cba0
BLAKE2b-256 87b221be56f23c5a4939d42ba6f7c6c7ae938f3edf3ec3af03ee878b619bed5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 83a12c825c757a88dd5ebe83a4bc8e5e15b4c679b8929a6e799aa721b9ada53b
MD5 f6b9d657b80d7da1bc7b97535aa69557
BLAKE2b-256 d5ef258a3f50784a8e191260f744448a7a4775914b2b36c008f292b4f5b238d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.5-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/6.0.1 CPython/3.12.8

File hashes

Hashes for sqlcycli-1.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 692eb635e52318a825e490cda9480cf647783314a3a3781b030271669f859f65
MD5 4eb8442569e80b246991e15a7c42924d
BLAKE2b-256 1ccdf45150bb1bb9a78e7148774c7573fdd518b700a795fc3215575052530499

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f9df76c0444950fc3b27a475692a71c3456f3af65bf6dc16d988758a867b7933
MD5 0d420af4ef4e3888ee7c515e46fd0810
BLAKE2b-256 e9e92ad2c683559f3a58eae360416a17e9cbd0eaec99a3464223fdf1f7053a7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0abb88e7bd9dd31513feb7c006a2df677357ea6bac1e98c004c15024c2e2324
MD5 8156e58990e85114d6638cca9c9912f0
BLAKE2b-256 b81fcf47759312a0669a4ba5d1cfc39077d0575bc777b62a19705f6b29ce9875

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a4e045c7089380d3a35e5987336853703f4b784e07be2464edcc4ecda091d281
MD5 60b5c2df62e25882c6beef9e7fcab011
BLAKE2b-256 6b857312b0b23c063dbf49717373d0bd622cce54d7e04088dbf9096a94ee342a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b9effd5caacc8557d44299ee298c0584cc38b3abd59c8d5e014a94d2ebf0ea0f
MD5 a86a7334288a30b04ead08ec2e256559
BLAKE2b-256 4ffe9f2f0bb3512578e5f6e1dacf88ae039e9635e106dcbe8609da1c93c5be31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2d6d857a4f1710f10a20af92206ee4bb1bd1157d179d568fe86528a02d801c57
MD5 461aada523d7e3bf63ba4dce7ebd19d9
BLAKE2b-256 7f346890eceaddd599c8c933cea620d5062e2d717f4891c1916307591baf245d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.5-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/6.0.1 CPython/3.12.8

File hashes

Hashes for sqlcycli-1.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4c4e70f8981acc2ca5c9ae69c5f08061546940c7c554ed9e60a4cc54bf4319c9
MD5 9067bb6cb4a611783b737e6d5bc961c0
BLAKE2b-256 3df0c2d44cce675553f475022f3ad4e9c440f2d0608fee2a654f352bf52edc32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a4c0ff971f2692e140b5b1a79ac07b8ed9e10ed18fc8f186a056a31f16df1e08
MD5 97efa430b6b57d9dd6d0810a4125d134
BLAKE2b-256 f9f9613ffa7970fe48f9f7bbbf99be2fddc5e48cea7ee2c9ac5dc3ea51e3794a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ecd86653880307eff99677de43c18fd2332276e0b3f6e8e60bc1a89d43477285
MD5 4235f967492b5eb1fa81801c1b2fb621
BLAKE2b-256 71de68fb45f6b84a7adb837d94ccce5103540352584bf0822f8289d70ea46231

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 92f2a9355f76da24bd4d45e942e69d33536af39c7e01f586104e917ef3be8ab9
MD5 f15bcc331a8eb36f9e533ee5ccbb41b8
BLAKE2b-256 819afacbf0a6caba20e7f7bca5db09827335712c9746554bfba9f6c8de645d10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 62bdc4c7a32c4d5cd057b5a68ec362f04c064cf945bb501dc06f4b677d58797f
MD5 cd362e1aac2af9fbd5c1b6a31ff371a0
BLAKE2b-256 6de1672f81d5ce5da0172db715596c6d445f8e8ff054a28cdf93824bb5c46fa0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.5-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f723df1a710e0c6baf46c7e2c2b0eabcf800e782218a7d39bf63e8174b4746f8
MD5 14787796eef2f7cb1d8dad504797ba8e
BLAKE2b-256 f2e7af62f3074e5b7a1566f0374e828e9328b8e28adcba90ce66c6d843a87bc1

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