
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Created to be used in a project, this package is published to github for ease of management and installation across different modules.
Install from PyPi
pip install sqlcycli
Install from github
pip install git+https://github.com/AresJef/SQLCyCli.git
Sync
and Async
connection to the server.NOT
support custom conversion (escape).The following result comes from benchmark:
# Unit: second | Lower is better
name type rows insert-per-row insert-bulk select-per-row select-all
SQLCyCli sync 50000 2.428453 0.367404 2.526141 0.078057
PyMySQL sync 50000 2.821481 0.480322 4.784844 0.335978
SQLCyCli async 50000 3.757844 0.340909 5.017284 0.157078
aiomysql async 50000 3.845818 0.419444 5.764339 0.333526
asyncmy async 50000 4.015180 0.484794 6.144809 0.337285
# Unit: second | Lower is better
name type rows update-per-row update-all delete-per-row delete-all
SQLCyCli sync 50000 2.597837 0.327441 2.251010 0.131872
PyMySQL sync 50000 3.044907 0.368951 2.789961 0.158141
SQLCyCli async 50000 4.226546 0.369085 3.994125 0.139679
aiomysql async 50000 3.792293 0.356109 3.589203 0.134762
asyncmy async 50000 4.160017 0.362896 3.928555 0.145456
connect()
to create a connection (Sync
or Async
) with the server.import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Connection (Sync & Async)
async def test_connection() -> None:
# Sync Connection - - - - - - - - - - - - - - - - - -
with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Connection closed
assert conn.closed()
# Async Connection - - - - - - - - - - - - - - - - -
async with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# Connection closed
assert conn.closed()
if __name__ == "__main__":
asyncio.run(test_connection())
create_pool()
to create a Pool for managing and maintaining connections (Sync
or Async
) with the server.import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Pool (Context: 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
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# Pool closed
assert pool.closed() and pool.total == 0
# Pool (Context: 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
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# 1 free async connection
assert pool.free == 1
# Pool closed
assert pool.closed() and pool.total == 0
if __name__ == "__main__":
asyncio.run(test_pool_context_connected())
asyncio.run(test_pool_context_disconnected())
Pool
class to create a Pool instance. Must close manually
.import asyncio
import sqlcycli
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "password"
# Pool (Instance: Connected)
async def test_pool_instance_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
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# Close pool manually
await pool.close()
assert pool.closed() and pool.total == 0
# Pool (Instance: Disconnected)
async def test_pool_instance_disconnected() -> None:
pool = sqlcycli.Pool(HOST, PORT, USER, PSWD, min_size=1)
# Pool is not connected: 0 free connection (min_size=1)
assert pool.closed() and pool.free == 0
# Sync Connection - - - - - - - - - - - - - - - - - -
with pool.acquire() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
assert cur.fetchone() == (1,)
# Async Connection - - - - - - - - - - - - - - - - -
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
assert await cur.fetchone() == (1,)
# 1 free async connection
assert pool.free == 1
# Close pool manually
await pool.close()
assert pool.closed() and pool.total == 0
if __name__ == "__main__":
asyncio.run(test_pool_instance_connected())
asyncio.run(test_pool_instance_disconnected())
sqlfunc
module to escape values for MySQL functions.import asyncio
import datetime
import sqlcycli
from sqlcycli import sqlfunc
HOST = "localhost"
PORT = 3306
USER = "root"
PSWD = "Password_123456"
# SQLFunction
def test_sqlfunction() -> None:
with sqlcycli.connect(HOST, PORT, USER, PSWD) as conn:
with conn.cursor() as cur:
cur.execute("SELECT %s", sqlfunc.TO_DAYS(datetime.date(2007, 10, 7)))
# SQLFunction 'TO_DAYS()' escaped as: TO_DAYS('2007-10-07')
assert cur.executed_sql == "SELECT TO_DAYS('2007-10-07')"
assert cur.fetchone() == (733321,)
# Connection closed
assert conn.closed()
if __name__ == "__main__":
test_sqlfunction()
SQLCyCli is build on top of the following open-source repositories:
SQLCyCli is based on the following open-source repositories:
FAQs
Fast MySQL driver build in Cython (Sync and Async).
We found that sqlcycli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.