TorMySQL
The highest performance asynchronous MySQL driver.
PyPI page: https://pypi.python.org/pypi/tormysql
About
Presents a Future-based API and greenlet for non-blocking access to MySQL.
Installation
pip install TorMySQL
Used Tornado
example pool
from tornado.ioloop import IOLoop
from tornado import gen
import tormysql
pool = tormysql.ConnectionPool(
max_connections = 20, #max open connections
idle_seconds = 7200, #conntion idle timeout time, 0 is not timeout
wait_connection_timeout = 3, #wait connection timeout
host = "127.0.0.1",
user = "root",
passwd = "TEST",
db = "test",
charset = "utf8"
)
@gen.coroutine
def test():
with (yield pool.Connection()) as conn:
try:
with conn.cursor() as cursor:
yield cursor.execute("INSERT INTO test(id) VALUES(1)")
except:
yield conn.rollback()
else:
yield conn.commit()
with conn.cursor() as cursor:
yield cursor.execute("SELECT * FROM test")
datas = cursor.fetchall()
print datas
yield pool.close()
ioloop = IOLoop.instance()
ioloop.run_sync(test)
example helpers
from tornado.ioloop import IOLoop
from tornado import gen
import tormysql
pool = tormysql.helpers.ConnectionPool(
max_connections = 20, #max open connections
idle_seconds = 7200, #conntion idle timeout time, 0 is not timeout
wait_connection_timeout = 3, #wait connection timeout
host = "127.0.0.1",
user = "root",
passwd = "TEST",
db = "test",
charset = "utf8"
)
@gen.coroutine
def test():
tx = yield pool.begin()
try:
yield tx.execute("INSERT INTO test(id) VALUES(1)")
except:
yield tx.rollback()
else:
yield tx.commit()
cursor = yield pool.execute("SELECT * FROM test")
datas = cursor.fetchall()
print datas
yield pool.close()
ioloop = IOLoop.instance()
ioloop.run_sync(test)
Used asyncio alone
example pool
from asyncio import events
import tormysql
pool = tormysql.ConnectionPool(
max_connections = 20, #max open connections
idle_seconds = 7200, #conntion idle timeout time, 0 is not timeout
wait_connection_timeout = 3, #wait connection timeout
host = "127.0.0.1",
user = "root",
passwd = "TEST",
db = "test",
charset = "utf8"
)
async def test():
async with await pool.Connection() as conn:
try:
async with conn.cursor() as cursor:
await cursor.execute("INSERT INTO test(id) VALUES(1)")
except:
await conn.rollback()
else:
await conn.commit()
async with conn.cursor() as cursor:
await cursor.execute("SELECT * FROM test")
datas = cursor.fetchall()
print(datas)
await pool.close()
ioloop = events.get_event_loop()
ioloop.run_until_complete(test)
example helpers
from asyncio import events
import tormysql
pool = tormysql.helpers.ConnectionPool(
max_connections = 20, #max open connections
idle_seconds = 7200, #conntion idle timeout time, 0 is not timeout
wait_connection_timeout = 3, #wait connection timeout
host = "127.0.0.1",
user = "root",
passwd = "TEST",
db = "test",
charset = "utf8"
)
async def test():
async with await pool.begin() as tx:
await tx.execute("INSERT INTO test(id) VALUES(1)")
cursor = await pool.execute("SELECT * FROM test")
datas = cursor.fetchall()
print(datas)
await pool.close()
ioloop = events.get_event_loop()
ioloop.run_until_complete(test)
Resources
You can read PyMySQL Documentation online for more information.
License
TorMySQL uses the MIT license, see LICENSE file for the details.
Release files for tormysql 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tormysql-0.4.3.tar.gz | 15.0 kB | Details |
Release files / tormysql-0.4.3.tar.gz
| Download URL | tormysql-0.4.3.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
061c7ce434967e3e0bf7e7b3e3032a479a2eac4cf623095db06f6ad64aa62b44
|
|
BLAKE2b-256 checksum How to use checksums |
dfb5e06e7f5321b118a05e42c88fb0fba91f698b907fa92eb24eb35e05bff2dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
|