Tornado asynchronous MySQL Driver
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anthill-tormysql-0.4.0.tar.gz.
File metadata
- Download URL: anthill-tormysql-0.4.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
346b5a16e83ed6bec7c82b4e6b22b51cc13c1345df497e1a49f83b4c17c8cd6f
|
|
| MD5 |
cad9e96c94759a04827aafdf566b2532
|
|
| BLAKE2b-256 |
9600c93034ff13941b8f3ff876dec15c780518250c51abc6012a8f44d29ccc85
|
File details
Details for the file anthill_tormysql-0.4.0-py3.5.egg.
File metadata
- Download URL: anthill_tormysql-0.4.0-py3.5.egg
- Upload date:
- Size: 45.8 kB
- Tags: Egg
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddc004b1218fa6ed9ff844a8ca4c580099d53f0a06ce05c3de62e4abae983f84
|
|
| MD5 |
1937401cb1fde5e5b995c3eb0963953a
|
|
| BLAKE2b-256 |
924ae91be683e7d09a4b986cff2762778d9d3c3c01768b05ee31c83fba72a642
|
File details
Details for the file anthill_tormysql-0.4.0-py2.py3-none-any.whl.
File metadata
- Download URL: anthill_tormysql-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 2, Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea910e3a3bcb2064639d7673e149a8589026646d6b2b23bd241b890762195911
|
|
| MD5 |
ce9f4034fa9078d666fa8ea6842d7d10
|
|
| BLAKE2b-256 |
d033d46bc7af16648da97aa8e56c78a8ad981695fbfc18a820e83ba942524d34
|