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 anthill-tormysql 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| anthill-tormysql-0.4.0.tar.gz | 14.7 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| anthill_tormysql-0.4.0-py3.5.egg | Legacy Egg format | - | - | Details |
| anthill_tormysql-0.4.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 79.3 kB
Release files / anthill-tormysql-0.4.0.tar.gz
| Download URL | anthill-tormysql-0.4.0.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
346b5a16e83ed6bec7c82b4e6b22b51cc13c1345df497e1a49f83b4c17c8cd6f
|
|
BLAKE2b-256 checksum How to use checksums |
9600c93034ff13941b8f3ff876dec15c780518250c51abc6012a8f44d29ccc85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.5.6
|
Release files / anthill_tormysql-0.4.0-py3.5.egg
| Download URL | anthill_tormysql-0.4.0-py3.5.egg |
|---|---|
| Size | 45.8 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
ddc004b1218fa6ed9ff844a8ca4c580099d53f0a06ce05c3de62e4abae983f84
|
|
BLAKE2b-256 checksum How to use checksums |
924ae91be683e7d09a4b986cff2762778d9d3c3c01768b05ee31c83fba72a642
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.5.6
|
Release files / anthill_tormysql-0.4.0-py2.py3-none-any.whl
| Download URL | anthill_tormysql-0.4.0-py2.py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
ea910e3a3bcb2064639d7673e149a8589026646d6b2b23bd241b890762195911
|
|
BLAKE2b-256 checksum How to use checksums |
d033d46bc7af16648da97aa8e56c78a8ad981695fbfc18a820e83ba942524d34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.5.6
|