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

Uploaded CPython 3.12Windows x86-64

sqlcycli-1.1.2-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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.9+ x86-64

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

Uploaded CPython 3.11Windows x86-64

sqlcycli-1.1.2-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.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

sqlcycli-1.1.2-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.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

sqlcycli-1.1.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for sqlcycli-1.1.2.tar.gz
Algorithm Hash digest
SHA256 bb7f69d1da6e1c97101143230e5ff0c990a7e128472d0be4c752431d9947621d
MD5 27bd9fd431def8d4f50f35461f1577ba
BLAKE2b-256 612ad0bcf25a34738c2c9e5e9e500d914d28e0161ba66eb605051f882c99228a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.2-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.6

File hashes

Hashes for sqlcycli-1.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cf430fdce22c1183eaa5ec483a237668ad3e930e90d42189ef20f78212fb71dc
MD5 5ea694b47057f734d73271f8e3bea771
BLAKE2b-256 a99c75f80c9124bb42b9286219fa07ca6df1eb0ca651c73949397e7c30cc336a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3c9dcc0c522e0bcb48a5eef00cc8f995628cbc7ef5d5ae7ecd38e689e2c7a24f
MD5 7cdef03664684b292ae76582ee30fb53
BLAKE2b-256 ce48eae81f35d0f4cfd2767a359fa3bbbbd9b227fe5486e0012b86f62a8d96ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55380f36a7c2024669acd70a8b73bb28b50870d5e5fe0bdba0383432d978433a
MD5 c3aea06edc74733144e978df620b277c
BLAKE2b-256 9846f15e2a602dfe8c3f31a29b8b8501be53697b0b0fb5c9feb7e51fb1f709a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b3d1ee9a78332451967599ffb937d202ba33b2d45d104402bf0a2428d285c83
MD5 f5e7d7b552c0e112f5da9f364906d1e9
BLAKE2b-256 140ead0f098cf27998388e956840c17d2ae7e87f465bd36580652214a21aa5d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 985b9aa58cbb2d4918232b3e55476c2bdff70816036227165dce1cc981f577e2
MD5 cfb8fd2bc63e573c648bce951ff2d9b7
BLAKE2b-256 74cc6eb18c4d026318e03f3b3fa69acab2bf4fe082a3f9212dd6a6eae264e191

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c0b67e2395f18a65b28626d1678faeed2b53886ca17088d26d8ff51529b00852
MD5 d26191f8db022741e7388c9411e36c29
BLAKE2b-256 7f0a7aca5d9b5dc86a489740c852d8931a9f11fa252cbbb1edaeed5fe0d50eb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.2-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.6

File hashes

Hashes for sqlcycli-1.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cac1ab213f6125e226efc10f1e8604d79f4b839a48d254763718f0f7fd92ec98
MD5 4b3fae2ed6dfbd16331be26846ada2a3
BLAKE2b-256 207ccacf6386940a97a68cfcef780597bf67243f999f22fcf5b14d8423bd884a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 87ea4e8f24ba000a88d9a9111dc3dd325ad182eb321f9771c113dceb54e4ae8a
MD5 747b50ecebc5384184878bb13d8e8ea2
BLAKE2b-256 29ed10ad3d6c6e8df0c5b80612b28788a24a3312147e168fb6d4a09168b22c5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be3e1999894089f06e63838bd7852b60e7acb045d943ea3b7b018c5b2a78b833
MD5 ea3ee5d378d014f0a976803b060e5f90
BLAKE2b-256 530bb53990f2deed3e2f2e761aff024923a7a11836af40966b995e25c280cee1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d39c7190514603f84311dd0f4f2245b929d05624de11a1c637006d90954ac3c2
MD5 3b0d72cb1c8c85bf155db6e24c66b251
BLAKE2b-256 91311079dd80edbe1666cf568eae76332d5e357811658819e405c8667b517a88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a9e89c9894403eef898f81794b762e2e057dc8afc192b6fe1baeb80b6605cfe5
MD5 5a5c1db5cbbd73fc2dcb3eb961e08281
BLAKE2b-256 493bbc3f7a460234d35e6a01a86d3f145782be83ff169684f69dfc06f7aa297f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 de53b8a28381fa130b39cd68b25b6a37ea6727bcf01d679d9f998c788f5c6d74
MD5 d37663fe388579646218c2ad9640dc97
BLAKE2b-256 381a97252f0bb5cbd73510ee74dfe64e0b02a36d4d3fa9ac67ce98a1d550ea6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.2-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.6

File hashes

Hashes for sqlcycli-1.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e5131469d67cef346afdf2eb568db774783102096c72c18935c4a596d6874829
MD5 2663e8ee30803695042f6354df713ea1
BLAKE2b-256 454564268d6e6ba3189a37af8006d8e6dfc935314d2994cd33b398f0787973b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6494c8961f9e98c02c3aeb2ef061237dfe64925aeceb4e8a699dc01889d970c3
MD5 0521eb8cbace8f0a36153a9dce58026e
BLAKE2b-256 1f937cf4ea7bd9c29e89a799e259c2018c5346f34d30cce91bac62b0f0fb76af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5eee1662fc896b4bf6dab6fa73978a6bf160669ac844367f49dd78df4cf63be
MD5 ae38f2571d28a7d08942917ea3576441
BLAKE2b-256 ee86f5312f11bb7eb7c7f7b636a6d2929ac762814696a6aa3bb1ecaf20f0e5a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 216383a56a2d060f8cd5859226c157e7a0c84d66e18d08a4fc848a79f2511747
MD5 e393f696edfcdf474842b956d03760f4
BLAKE2b-256 3b9ca9d070ecef4a1d2afc547b6fdea556d762001331e653d7829e9709dd4f78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c3f086fd788404286d96cb9bb85f1c964c3f6504879173ea7564867bf5138055
MD5 a0e6e9acb999aaa8a70aafdf5e21878a
BLAKE2b-256 bf16e704ad5f6aeadd360c963aa1118e3410cac93174d030903013a1f07c1f7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6890c745115cab07695a425c13704beb568eea6784098287a583c8a99d9d1cb5
MD5 beb3748e0b0e985fd833472b009866a2
BLAKE2b-256 da4e4ca34e81656d4da603e72693203af0fb305d6b4e14a9848071da60be67ea

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