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())

Use sqlfunc module to escape MySQL function values.

import datetime
from sqlcycli import Connection, sqlfunc

HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "Password_123456"

conn = Connection(host=HOST, port=PORT, user=USER, password=PSWD)
conn.connect()
with conn.cursor() as cur:
    cur.execute("SELECT %s", sqlfunc.TO_DAYS(datetime.date(2007, 10, 7)))
    res = cur.fetchone()
    print(cur.executed_sql)
    # "SELECT TO_DAYS('2007-10-07')"
    print(res)
    # (733321,)
conn.close()

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.2.0.tar.gz (3.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.2.0-cp312-cp312-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.12Windows x86-64

sqlcycli-1.2.0-cp312-cp312-musllinux_1_1_x86_64.whl (21.9 MB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

sqlcycli-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

sqlcycli-1.2.0-cp312-cp312-macosx_11_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sqlcycli-1.2.0-cp312-cp312-macosx_10_9_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

sqlcycli-1.2.0-cp312-cp312-macosx_10_9_universal2.whl (8.4 MB view details)

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

sqlcycli-1.2.0-cp311-cp311-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.11Windows x86-64

sqlcycli-1.2.0-cp311-cp311-musllinux_1_1_x86_64.whl (22.1 MB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

sqlcycli-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

sqlcycli-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

sqlcycli-1.2.0-cp311-cp311-macosx_10_9_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

sqlcycli-1.2.0-cp311-cp311-macosx_10_9_universal2.whl (8.5 MB view details)

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

sqlcycli-1.2.0-cp310-cp310-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.10Windows x86-64

sqlcycli-1.2.0-cp310-cp310-musllinux_1_1_x86_64.whl (20.3 MB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

sqlcycli-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

sqlcycli-1.2.0-cp310-cp310-macosx_11_0_arm64.whl (5.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

sqlcycli-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

sqlcycli-1.2.0-cp310-cp310-macosx_10_9_universal2.whl (8.4 MB view details)

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

File details

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

File metadata

  • Download URL: sqlcycli-1.2.0.tar.gz
  • Upload date:
  • Size: 3.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.2.0.tar.gz
Algorithm Hash digest
SHA256 f8eab7bc145e74f09ac06e9ed09ef8f91f68575b3c17b65b8077bb9506d25ce5
MD5 0d383432449b6a01d86d424dd381b693
BLAKE2b-256 4f8371318a5120c9c73d89edbd8954a5b7f01eebe9dbcd33490d3f3e252c121b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.0 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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3e21a3e502c2dad888ee5990ae7527f7478120a6e3ee1b1b0945a7f0c588f73c
MD5 9d34a160309da36469f08e5cf6e84520
BLAKE2b-256 416489b055d1c0ee58b24523d684343bdff0518f503ff4af2006c8c54af94e3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 faeb72fd803e2917771f3ea45b4010f358c5cf3c1a76f10465e2286ddeab2235
MD5 d6c86f7b3be44dedbd3be794a938742a
BLAKE2b-256 29096d5ad3d22f95cc307ce95f99d593953da0645ced15ba48e6f9d5cd6c6bd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd18b03e50cb1c8f343780685e9fbbfcef67b27c96ab95b3e9a0825bbe8b8797
MD5 cf5233f243d5d3d16c2d151d1113fbe0
BLAKE2b-256 0fd3c54353e7ef2681c3d73cd1cad80a2c25a1fb1d135879b87293a26991c646

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b21f97cd04a74233980d7a9c5e8d65c0b93554d2360f65631e3cae2718d231e2
MD5 9fa178d5dfe8839df2c34f8bae04bbe3
BLAKE2b-256 081c8006cf4f1ae8d94115d3cae1e846803f02a181a345eae9eb46f54e7dada3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c79599e52e4b7d42c52a2223b1dd8886e41e18d3e2df382e084dbb15c42bf2a
MD5 a1c892d6ed39bd2fcdaf35dcfa8ba93b
BLAKE2b-256 fb5fd2fdcd3993301263ca4ab6fafb74e012bb7affdf022e008a7b3efb7ddeed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 63142f1972ecbab81e4a507ff0525f31b9eb54274f2a0d44abcbb37b0bc41ec5
MD5 8f68ec3e33cae235fbdfba3c9d5948af
BLAKE2b-256 75cc8d04007e5326720db9804ed6ff4c642ed99f9e823733995e0db4f3f1c5fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 4.0 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.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a47a7024b0fc47e2c1cbb48da6651b6bbc163fe7916f3de2a30c9ca598d6b115
MD5 1c492f51c24779c3a861f837b6bff821
BLAKE2b-256 bed26dd8c912e3241bdec11167914cf1fc9e6ae5a2fc7b2793ac0e71ed2c89f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9b23974174ca5e3adcdebbe7a01fefac8378fbab725112d631573d38bc4b108c
MD5 5607f0617006aff90e20849fe120c100
BLAKE2b-256 709843667b6f0071b327b1dd607c92629b8230d2be28e907e8dd632c72e7daea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b402ae2d746b2901a7c1f466f4b30a70cbeff9a45241212641fb3dea5e05229
MD5 3bcb2de424cb949d1de66bdf4c3ceaaa
BLAKE2b-256 7fd96b46ee7bbb84f39feb5744053fb4675c02f43f08d240c75ad92d0d950349

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 731ff095f99a814a052540ff83435b3d57e1f7eb45801c488cee3edeef882637
MD5 1193059b2a63934493e27caa27d34f93
BLAKE2b-256 09b920b93eee4b92a3c80787c2639dd89360d81684d407e9a475de74c63e3c4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e7ba99e9a49ac2d2c047919c08f770d6af11676d9768a6963eaec951fc3ccc48
MD5 d5c39dd30d079c894c5a93b1609ca965
BLAKE2b-256 f6dcb5d55d73a2327da20ea2de85feb049e5adda366f6af95583986d8dfcb2a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9e80a2777f22bf184b5f90fe1a5514b7e39285caa0774d46e3b03813cb3ce76c
MD5 37812c4c91afe522f03ad01be3632e91
BLAKE2b-256 f2e6658c5f5f75efedcc9a77a0f4b025dbd98f4045231efdbd2e98056f68f7e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 4.0 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.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f68e63d15b6a688de0b767cb247b7ea084d169e948977daba317f6febde25dc9
MD5 b5f3b65e03eb8f35f54d6e31393cc1db
BLAKE2b-256 0ddd35bb6f66dbf61c621701a250c095ddb0d8ce66d6b594874a92b384c8e811

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4af011273a610311b0697a7e2b89a25c4860b8cb444f257f77c4414b9c9ddc67
MD5 d841589f4ea42017ff39859fa0cd3cd7
BLAKE2b-256 3f70c59770f58716228a1a2c9b3dfdf3d8d7d9cf59735f24b64e9e08cd3c3bf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76eb1331d62b1ab4e758ad32c8ba0447e3046356bea382ae6fb796d7fe28b012
MD5 019b78ccfaabb3c1b7baff4aacc0a709
BLAKE2b-256 a119a322d36d2338e3aa711430d32f732cd549d3245f46f5b30a6f5880914949

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc76e97e2fcbb658596be22d21d2d5c46c601f0d365207f8f624c26aa913efd0
MD5 7e01c251609d9ddf739b38e5a7090ba2
BLAKE2b-256 06ce00f7147db38b15616ebb33094cdb7fb8a16c2bb3bfba33cd0585b12d1163

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 860dde1e5870678573ce9b7534d97bcc8d85fcae96f6d36f83048bcac45c46b9
MD5 7d1f69e5df292c9c3109cd95ed528f99
BLAKE2b-256 6acc1e869f917bcea1cfaa680ba1741d82f62f58785dcbe2254d19289181790e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 48ce151ed322f69d1b3537f448a542796cfa757a62e7a2f204dd4ab8332d0814
MD5 880a7ac0910c591277398d5639696e6e
BLAKE2b-256 7456dc8dd37423d87448d8d9c48e97003264f626689c1fffdcef7d0c673d5055

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