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

Uploaded CPython 3.12Windows x86-64

sqlcycli-1.1.4-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.4-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.4-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.9+ x86-64

sqlcycli-1.1.4-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.4-cp311-cp311-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.11Windows x86-64

sqlcycli-1.1.4-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.4-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.4-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

sqlcycli-1.1.4-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.4-cp310-cp310-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10Windows x86-64

sqlcycli-1.1.4-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.4-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.4-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

sqlcycli-1.1.4-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.4.tar.gz.

File metadata

  • Download URL: sqlcycli-1.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 d3c2aa2cef9b491106bb374e3c6ecd6fb2c7b149621f4d7a5acc23eb58776afc
MD5 a61c1a57d459feddb567678118a27b13
BLAKE2b-256 4fb496da92b10438447074c35185da8dc2daa025ee98cba8ced1aeed9193af7b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.4-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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 51669b9660cb8eb22b7148e2e6fcd2a38933ec4fc4cf1685de55c400eeb21545
MD5 41b273f194754d8f571d706297337f0d
BLAKE2b-256 a8ab98864cd82ef74b04cf0b6a7372088865289600ed4b6bef0643ededa19314

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f394e0313f7361f3f58b6e320a2139b2317237667b3df1e957eeff6305e15d0e
MD5 39ecce89bee6f180433b13ba4984f32d
BLAKE2b-256 e43925dc74b4a2965a0148d1654cc49e176cb11a07daa2a8e838025c55d45b6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e3421ced5fd2d6451c161bef7518c12ef57ea8f4ad0cdb5fef7d3d934b66745
MD5 5e4b48c701c18c116c20826192574bf0
BLAKE2b-256 b56a1e15f79f0a651c969e6e663c9e6492b1550df982ec4ef4d5aa24e48466de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ced60d235fb6deef62485214efc8ad4959f88b4e82f02eda195d596161cd94f8
MD5 d832064bb3143613840dc3a92a7c8ace
BLAKE2b-256 f4d1f9786e8ff2c33be25d85a1035f77e657bccedac7f53ffa225d5dd0027e1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0ff8ca55571273d2f484a3bf4490f430291e33b02a546609c67ff50f8422c72e
MD5 d36e86322ea1c3d867d0de0d04fa431f
BLAKE2b-256 04662331fffd9b9ce16a18edf79f84c94dadef83f31eef5b2617b88bc92e46c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 cf9de087fb000a60407777608cf63ea5a44ff36d553c35153ea65414344e68e3
MD5 4a7e003a0900597f1a374a87be7ba333
BLAKE2b-256 2c6bdae2b9724a20f855059986df0f8dee7e5f970ce3c1e046cb8a0f58859613

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 81fc775a2253e3ee1424f020bf09cae0e38d0ce6c9d6dfd552e17b95cbbb1dc4
MD5 111bb09d844230f851973c63aba862da
BLAKE2b-256 a64944476e8738c7b3f5dc136f8852343cf85cd4caf339bba74bf26d29a0e5c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9c2fcff871c4756a8c6af521b3a41d4523ace5d8a5e0d8e025796438142d66a0
MD5 0aa524efa6056c4ceb4ab1a0880d4f38
BLAKE2b-256 102c0a510456a0ca4021784a08109e32d1cf1b4fc59938cec0ddf5c58fda223f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f41c585f782f27c3c35f99dc9eb4226007c859281dd2bd6e5bc95644d337d42c
MD5 be35f6bbf304ea220224205fa5bdabc3
BLAKE2b-256 5b4a0f425215b37342f4cb43be89bdd1c192f25e2063eba80466cda6b5c2d739

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c5286fd64b3675fd1e8651b04760f62ee6821ebf166d7e50d06e3fe172ce84c
MD5 8f539f8be672c3266db8056cc31e5f3c
BLAKE2b-256 59733ebbd96d3570d4cebb787571cce7448efef0fcf60a96565f0d5dedee6c6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b550a7f11fc5da9eec73b9a07fd00f9f96309ef7e03244c663595463871944c6
MD5 d99b66eaa295f7cb54e5e31b8b933e57
BLAKE2b-256 f39c0f9871cf77fd5159ce69776ed3676186348254188f598ba0d89951b514d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1f77a0a0a7b8372bcbb2579847598b628acc6c6c9b3d384cc73dd259e3f867d8
MD5 747cad575f217642c1645bbc24957ffb
BLAKE2b-256 b1ede5a657cc126f374392d2675b881da2c712de057680b110da182485db728c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4a9b6acfa447dede991e3978a369dd9322a36aae4d62d50f82ab3475f6ea38bd
MD5 dfa0117e7666f1765a9e35fe24fd7913
BLAKE2b-256 e437b695b5392ca1a0348c53401cd7e05651d08f45bfbacdbe9140e20e5ab025

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0d5b9794feb9b6aee39bac997a51695ffca36563a532ebbba73ef1b7b0795163
MD5 3625da1b469e6d0f3c9c5d33ccbf0ad4
BLAKE2b-256 e58364316c979cdf89375aeac17219e635d1bd3455e1661fba2ef849ea2e36a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 266bdfbfbff9fd1628e6b383c10cc6481832a6039ca3c1707610ad0afa5a42a9
MD5 289cef1a18fcf2de8075b12bb04f7ef3
BLAKE2b-256 ae484d8426c4c63b23a9caba4fedbf0957edac1cf94080e9d3842a226463323b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4d7961e7af1f2639cf9395c110e6dffde159379eb8966ec23e769b39a193290
MD5 4fc1143dc8935e609b9fe4a98c66302f
BLAKE2b-256 075ee74cb473f3a9080ecc7c856f1091bdb3fc5892a1bc38403320d7aea1c0a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8c1cdaa363fed34dd20010f819a30787975fd3216441ac8f149521bb500447f7
MD5 76fe1311867a8990074eab9f06377da7
BLAKE2b-256 bdcc01dd262fdec10fe7e0b6cf013b219d65f629a1441f87cf1ca4172d1437e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.4-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f2bf3276cc6662314704a8145eb170aa5d0ee4bcb3cd5fb1e90c806dc44d3b18
MD5 80155fab4e41e68278c7b51bcda61000
BLAKE2b-256 287c4ae7d22a257d3d3a4a9eefca366605d6d716a6b75a3d4f0c954d7e28364b

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