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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.9+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

sqlcycli-1.1.1-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.1.tar.gz.

File metadata

  • Download URL: sqlcycli-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 71007137d4712be530de97fdf55b5fc22c33b92f9c62b0a71d409e31459b956a
MD5 af3126a180175b9516682c9c964fb02f
BLAKE2b-256 9b250e39cb309df2862e77cb955fbbef18c6d45d431f232f3299b3de8f8f4828

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6e169ff04e9d7835c1fff672c3f253d871388fbb1b1b15de6da004b842a96db8
MD5 0e978498639c42f9e21053fd5a513b02
BLAKE2b-256 87455a029e908166a8727d5c32f361fea4bbbfd2e0bf7aad905e0041b6558e9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 68c5205834f66d9ac7b6ed0fa1c1e439f916150e5735d3cd7279dce871fe0b92
MD5 02576d883a0687cbc3cfe1939b768463
BLAKE2b-256 de6ee97fd74bb28b510284a24c8bbbfa14696b520b8e1b565efb2617b7a42686

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f1dbb7a6f15aaf41c93a7c50ee1a8020c837c991ec141305ed9d099d40af797b
MD5 a75d345dab7f0edfc6e21b9c1bba0d9c
BLAKE2b-256 07db2a49ad4de65da7d26332e7b582ad28eebd5ed16f2c61e0dc320917c9e44b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9503ef2aae73faa705e82bde0ed106b52fb49b33318183865bf2c554ecfec79
MD5 bfdd8764ceaa77126b7ccb19a6fdce65
BLAKE2b-256 7a98101f0a1fd7404c54e4cbef9b2bc7851c636f014ea9c0a499289dd0487944

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 719dba0341848e7543833c49bab7d08664e251876568955d5c6febab7e84adfd
MD5 c88c3bd2963c843e46fc7200f4812693
BLAKE2b-256 d751351a9099d2074ec568385032bad1257f4dc1ef6c78d817c001fdf8ea3a53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3b453a848fc65dd545f591a4a0d6b8c8a647f5d548f04c432d6dc71971dd4d67
MD5 2f36f4a90c68e9ffa084de4935417f62
BLAKE2b-256 7f7528e424055d86f04cd71356e83f3b034844541746b7288452466c9dbdabfc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3ca87801acdeb4fa62767c4bd82a519505c35b22670bac73c9067e414789d827
MD5 13995dabd0b1dfb9dbadadbe3985293b
BLAKE2b-256 2e4a291bae67ab2f9896d3b5992a73f36a283c3aa468d19ac3877e536f2aaf55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ff2bee21f648d66b9c8861b850190140f43d95a2b32e3d10ad0d90c5c4878532
MD5 e85eb3d12186d954e6230c7f0a2c9f8b
BLAKE2b-256 605963df3fe0e45a2ce9bf22399a4100bb0fada12b33d697580e5f2fb314b2d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f9f53e0f860c582e49b93a79d5018f0277bbff43bdb184b304b3376d352ae313
MD5 f104ddc4bf850b6faec701413ef4d6b5
BLAKE2b-256 460060d07b25ba50f6c40671ecc5678724b7e0ecfe68b66df68967e78006185b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c80b968d8422979efa3bd97c361df4edf7b4442f39375bf3dfc39939344cb147
MD5 8bc8f0f11103ffb942639928d7f3025d
BLAKE2b-256 94c687858127d78934f963fcf949ff7fc867615f4887a5154190e063cdc25a4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 030f0110d707ac26b8064d31079925fc2915c23eebcfee3cea32ea7036cc5a31
MD5 4addc9ecf260bd9d1aab875cffc1e913
BLAKE2b-256 74b22cd97b2adc313f133a052fbf337237bb02c91436fb53f7821f3a4d5a6a12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b26ae11733612950a436509dd2cd88d1ee6272fc0709907ce9b2ce5e57228f9f
MD5 799dfe360e76a86a6d5a112e9faa201f
BLAKE2b-256 437c392c5be5120acb5770a28664a2d1a7866e69e5017af9a6daed6638e1c8d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlcycli-1.1.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a8323f568425ca9851507c86acdd9f93a94252336be446ef124ab69c8dd45042
MD5 aaee1ef0a44334a9e24c1fb3f882b8fe
BLAKE2b-256 75f053ec44f5db6396f06b9ad78d7f9be2fc8979dda17e0efacf2a7c1bbaa40b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6c16069714568ca37f5a59938a55af70135cd18e04f17b9ed1e451a317777529
MD5 db3c74ff703cde54c059a3970c061ef2
BLAKE2b-256 ac85cb91c2a62cbacf6816e8134979183a7a650781780295fe3b12d448ffed0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33dbec31fce47d0b66b3007a2eec0270bff047632fb50e243364708e263d1e62
MD5 8a5851bcf332de272e55e14b05a2049d
BLAKE2b-256 2de1d8944d51b60ed2e71ea82b66347c24d467a7a3978e10019073e5185dc6e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 930a53521f71e2ac3b6cc4a8d3962a402e2aa81c2d739204e3fac7463b67adae
MD5 d7de9b0026c65e70d99ba10f4c8fff20
BLAKE2b-256 3a4ade02ba8670801b1d471da8308aff75592377a1b0e7bccb7b3e91eb82ee23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 87bbac926edf4dd697d837151f8cc513a33d828df25b175bc3d9a83a28c8fa85
MD5 2fec4ca8e78d6905e1a9016687ae77cb
BLAKE2b-256 556a5784fbe1c7867bc7933644aa1664d45bf945b7fbe59cb2880ded4ee9d2ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlcycli-1.1.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e07fea8974b507a61a223ead112d5ff73a3538b95e6d3d0a031b3ebc98bc7007
MD5 9eb32973af8e367ebdd2931ce876d970
BLAKE2b-256 2631ab4bce234d4595b85318faaa51a7eae72c9bdcac9a7b4056f6ba1bb5821f

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