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

Uploaded CPython 3.12Windows x86-64

sqlcycli-1.2.2-cp312-cp312-musllinux_1_1_x86_64.whl (22.0 MB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

sqlcycli-1.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.9+ x86-64

sqlcycli-1.2.2-cp312-cp312-macosx_10_9_universal2.whl (8.5 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

sqlcycli-1.2.2-cp311-cp311-musllinux_1_1_x86_64.whl (22.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

sqlcycli-1.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

sqlcycli-1.2.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

sqlcycli-1.2.2-cp310-cp310-macosx_11_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

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

File metadata

  • Download URL: sqlcycli-1.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 c7fdf9d5546d628b93fffa6789263593bb51e6d582fa822d2200e256df749bd8
MD5 d9d1f8bf9950274580351cb1be68438c
BLAKE2b-256 96b3bec612d38a1e090e7f15ac8f70618d058c22c7f47b59202e3defca2938c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.2.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0b0a3dbd1de558c0f9551c428b4a646e377cdb981b19c55591ddaa71f7bb8f05
MD5 8a4278109f9959cc55b96773c39156d6
BLAKE2b-256 30c15a06fca5c50a29297d23cbb29bb5687179d5cd87ee29751d7b2b251af466

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1dd2d0b7b0564d56104dce7f20a83ac4ada442371e99d5d8476d3b2cd9f1525e
MD5 5f80a8b15645b265b232e9160130089a
BLAKE2b-256 483957bcd3e903c36ec1dc57a9d5ea5eea8ab6d7122fe36fad48ad64b91438df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a940a6a7c43898ee92f90efc3142b53999227f29ee0a56f2a9723d2cd46fe9fc
MD5 d4b1fd0bbbf67dc3b4d8d03708f74bda
BLAKE2b-256 4b9f9e67a63109b00791feb6288e2fd653fbb2a60e9303a964e93a06ec8eb7fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a13a80d3587785a570ad79271d3d963a3113c979a58c4726c8c990a303bddb36
MD5 ed7d6d90ccc5f782e52f13ad8dd02760
BLAKE2b-256 cf253605d1ef1c1e2338e30d0de031f2aac6074d1026a8d7cee02761f0281869

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5992a1374db34c9644cf70d4b019e4dbe0e00e94d772a5bf1713990903730235
MD5 4090433dca36ad53295d45b543fa8b6c
BLAKE2b-256 280b7d559274b5538b77406776d1bfb6a5bf5132d15c7e7e136081e27040cf38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 bf2785656d8183ca2c1ff29eca405b5839be3371c0ef319dbfce37b870fa69a7
MD5 093b31ef199c814b0cbf158793e632f0
BLAKE2b-256 0eafe1ee6cd800f753c6056ed62e23d2309086a389dc8d9103a00cce3446e2dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.2.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5a520c44d57da2614d3e332de71220c2a2f1502de38b47ef85b4ac3ed96fa430
MD5 cba5dae903861fdd5b8257ee9ad02bc5
BLAKE2b-256 2bf41efa569e6cb96de55f5729c636faf9c371fa7dcb6231e25962d8d94c29b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 b5f01d4516e88d3e77b2a00eefe56106dac5ed377988915323046be33d51c61e
MD5 68f9c848a73c3e16c18141a0ec6e5027
BLAKE2b-256 13b7510d4c065fca70887ad2fc216082e19004dcec2e1c1ca8030241cfe9b464

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 40bfcac311b786f6457239caee7d41549cee7d841ceb20e8530cabf955defd88
MD5 5f1b72534a8602b1935a8d9f3d4c4217
BLAKE2b-256 fda8841cb4f734d58aa2d9d889cfa29cc55f5ad15ff9a58ead8ee749acdbc54e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ccf7d4be401ccf4455210828c8af9e1996aa63fbd9f82c3324bfeb812070481c
MD5 f7f4f9e23e6566db8230b8a3ac2f8aa5
BLAKE2b-256 575f391b84e6c7ba5cfaf76042b6d64052250aeb2b58bdea5f714a272db18b55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bcea73c1ebd88345bc94520e178dce0dea4952d3a6b95486d75602909e4af040
MD5 71f968e8722f42738e21c2f7e0d23d24
BLAKE2b-256 c778961509562bddb08e63cbdc01703dbcda7f7a04bf42fb55bb95f48a903f9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c80a13c3fd209f014677db9b6a0b66c8e27850699da4935403b70bebdaa6cf34
MD5 348fdca68913531b9ab6625b2cbd48b3
BLAKE2b-256 6295e1584377ae0199a5f680ecff91d610a7a256a2c40fc1d8f79afe69ae15ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.2.2-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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 885e75a48acbe00fb416d0c9f1ef8365eccc51f8e2f84e69ce2f7a7ad8064add
MD5 f125d61e5aa0bd3ff4fec6c36dd50b64
BLAKE2b-256 978c6ee6095140674433c43e8c178b4e2aa248df8c649740cbb11e21141c0d12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 aa7675f90d0f970dfae9e496befd2a8f8cb9e73dc978eb5397b5b82e3cc9040e
MD5 27a47583a8e957342d45a27b2b54265c
BLAKE2b-256 3e4057f61cdda0431cd037b5a458d1c64f13593cffe066df9bdd3cb93b97c2f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9140a7d3aaa5dffdc41dcb20ff2da75a7a17ca9427089960b39818a8462e2eb8
MD5 d78e429cf184f20be0db18d1a83eb6b0
BLAKE2b-256 29586d453ab344bf24d149d4f413c5c79ee04e6ffbb9411cf563f8eba8eec230

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fbd74242b5f72d0e0f79532b7ae1af4ea173b3f5b74f9774c58da10ae78b0043
MD5 ff52530c6b6cc1d4058718cbfba06218
BLAKE2b-256 87773238ee01bded8c44392fc15a933074250401a00768b0b7a75a601103424c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 822dd616e9cd1f3a8951ab2da62d796f4a02da17d9c55f5f7146d6156a0678f1
MD5 082345b0ae3014b8bbe4aedb1d8259a4
BLAKE2b-256 afd4bcc68a443028e05dbc36f62aa6668456611ea3197bca917b382e9aba8a29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.2.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b90b57cd8c6c8fc9004e922604eadf2aabea56db0cb7407e111625a259a9300b
MD5 eda292e3d71f6e3011da99956341a092
BLAKE2b-256 d6444ec86f56f1c658f80851ab486fd67be3baa1224fef2e1051456be472b4a6

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