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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.9+ x86-64

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

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

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

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

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

sqlcycli-1.0.9-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.0.9.tar.gz.

File metadata

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

File hashes

Hashes for sqlcycli-1.0.9.tar.gz
Algorithm Hash digest
SHA256 7641ca7d2c27ddc28781b59f60c073618b982d856b92f8f97d354eb6d1a99064
MD5 0dac9c498507b7c54de88ad89f08f5a6
BLAKE2b-256 71ef9ea1a8e63c953c21263dad480f458b57a06265e48f49b8134ce50e3b5f5d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.0.9-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.0 CPython/3.12.5

File hashes

Hashes for sqlcycli-1.0.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 11a7659918093814cacab9223d0f061aaf140c60062ffb8028981625e1ee6eee
MD5 c4de6bb677c74529725f6043d5f629ff
BLAKE2b-256 2f2c3bb16f793242e107c75bd8a2bee032ea8bb788c269020579a73d42994d9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 7d831efbf14dc5a8bf13514b6a3997fadaf95265f01dda4f976da64a5ecf2596
MD5 01821cb2158041e396d11e97a5a42d16
BLAKE2b-256 1f7fac4c8a6cd4f7f855cb355d034e81a8ec3d3e8c6de306ac75a451d029ee62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d21607b50a4a8decd89e263bb623ef212d041e081a6f15803a04b665d43b816
MD5 6da51594130a354947cba131acc340be
BLAKE2b-256 39030e32108439c0ceec80bcef4b8d717961c7dd5f653c6948020c744a6e9ecc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b74e98910b4f9b9d904c7f9094bfff427498c5f1f411ad915ac57e59031d354f
MD5 527ad68ad9a2213b1f56839b32870f3f
BLAKE2b-256 1f9891caccff7524e1b1d1ac1daff200ccf6abdf03a9aca1b42325255c76edae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 48bd575231fa8c307e86410366a0d8864e3e223ca028b0d86ed57083cbc2c32e
MD5 8381d18e1685ca79306323d980a9dfdf
BLAKE2b-256 b0e1de2a0a92cb6eaa680d49f8b6a9981a98d9f8a10e9417d62e73ab70a35c46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ab8a3209a75480b9c4a0c850f2fc499068dc3a1e4ebdaa8837f1dd95284947c3
MD5 96b29c219edce76604c89bc97188114c
BLAKE2b-256 a87a16dc58c5ba77a60482a9c635223a50e0b966bd4b2262f00486a675b41d6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.0.9-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.0 CPython/3.12.5

File hashes

Hashes for sqlcycli-1.0.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c0abb0afcc499d94c70ea3e505bd5eca12740875df09fd826950b268bf26250c
MD5 629f27aa1c8efde77d871d62f8dcaa9e
BLAKE2b-256 13b9fa8cfd7dd017828d79c2b19b8a129264cb89247a020a1ddd7207e02d4c0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ec5b41a9c78a0b2a35d3c07bd28c15ad2715a07d885ac19b4cd6784bafcf24dd
MD5 58b2ecb938ccf62aff80876e3904200d
BLAKE2b-256 e72a62298399537d4907baae297193206b83eef81fb6a269d6baa8fe87ad0d85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd5288b1ad78875b31789c2723bdd639dbf2bb0739f3d56fd73faaff0302f641
MD5 37078672a1d3f6d8a024355dbe8f79cf
BLAKE2b-256 57a40dea6d72b66e01b974b407f4b44692de81c4f2b0d47bd36ac55fe2734db6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 238986680218daa2cd0856aed1901bb769a7ce40fbce81d4aa41a47519960f8c
MD5 64756d3d0d2c46d498764f311e0d5cec
BLAKE2b-256 e0a1a9aae02759ddc92a7a9eb2482769bd2b37412c5ec8ed7d7500f0eafcbf17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6998e16f901d5cd4766969bede501132b5a6fc27e1a4e06086f95f70d4984f76
MD5 ea0890258ef0ca69b88e2fbeef2ae00b
BLAKE2b-256 3029ea4f118deec9ae83da296f3c12840c54642f57973510ec62e1e02b63db27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 45bf82ba89bdc549d0b5acc603c417c3d5f88716959dd9a47dee3617cb225bb4
MD5 1362f854950de1f3db5c1ee88481fe58
BLAKE2b-256 38d60fdf1d3aa26c837acb56137df13940d3f669d8ef1d7aa27d39ac8c9680fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.0.9-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.0 CPython/3.12.5

File hashes

Hashes for sqlcycli-1.0.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2a0d1512ebd1e1f2fe59e5ef4556e06a34ef7648a8e6320bd7672d4fc966836b
MD5 8ead17fcd9c3b1756c6d7f774211ed69
BLAKE2b-256 2b1d205ab0322e615ceefd3f087b39da1a16f9c43d632db48a610b4afee675c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2d7406c32b70859f6aa0b8f526b83d56266b9a08496c067c2006bb9d44c958ad
MD5 87c791d84a6f2227bba344344596bf88
BLAKE2b-256 49885ffb1d184c02a2c01a6855520f37d6364453e7e399370ba49f7917be8469

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e8faf55b518a4365fe778f6f0bebddbb4bf12541c34bc53a916ab4c278336c6
MD5 7c12275fbc231baab00d1a2f32e28e51
BLAKE2b-256 4e4184a314faf59cc64a55f06ecc997dab1372e164371ebea915bcd3b8f0e6f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af1cea8da825f6dcd2c0efe1ba5ca8c28fdd76a74377c581e2dd21f86e2f6a33
MD5 35744d5719b00008b551ad8d866406be
BLAKE2b-256 5f4e484878f8131825104df93afe30a406dee82d154a2ab6dbfe3f45e1bc37d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 56546bb7039b22d495d5b3d2602431576e407d7808e51cf936b30627e3b3c48d
MD5 3312fb54d304918128fe43ca0abef19c
BLAKE2b-256 42c5fb21252d51fd4a6485844b20622fd5d4616b58238f9a72e1177f41063e34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.0.9-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8859afc6a1d30bb00fc0d2abf026f0773197954e8017b068cd5babbc4d7163e9
MD5 0f8f7b15d85d7dee5df4b940bb904bad
BLAKE2b-256 b53628db94271911e18cccc74a072eef5919665a905fb08881cf0353b72f4f5f

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