Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

aiomysql is a library for accessing a MySQL database from the asyncio

License

NotificationsYou must be signed in to change notification settings

sqlalchemy/aiomysql

 
 

Repository files navigation

https://travis-ci.com/aio-libs/aiomysql.svg?branch=masterCode coverageLatest VersionDocumentation StatusChat on Gitter

aiomysql is a "driver" for accessing a MySQL databasefrom theasyncio (PEP-3156/tulip) framework. It depends on and reuses mostparts ofPyMySQL .aiomysql tries to be like awesomeaiopg library andpreserve same api, look and feel.

Internallyaiomysql is copy of PyMySQL, underlying io calls switchedto async, basicallyyield from andasyncio.coroutine added inproper places)). sqlalchemy support ported fromaiopg.

Documentation

https://aiomysql.readthedocs.io/

Mailing List

https://groups.google.com/forum/#!forum/aio-libs

Basic Example

aiomysql based onPyMySQL , and provides same api, you just needto useawait conn.f() oryield from conn.f() instead of callingconn.f() for every method.

Properties are unchanged, soconn.prop is correct as well asconn.prop = val.

importasyncioimportaiomysqlasyncdeftest_example(loop):pool=awaitaiomysql.create_pool(host='127.0.0.1',port=3306,user='root',password='',db='mysql',loop=loop)asyncwithpool.acquire()asconn:asyncwithconn.cursor()ascur:awaitcur.execute("SELECT 42;")print(cur.description)            (r,)=awaitcur.fetchone()assertr==42pool.close()awaitpool.wait_closed()loop=asyncio.get_event_loop()loop.run_until_complete(test_example(loop))

Example of SQLAlchemy optional integration

Sqlalchemy support has been ported fromaiopg so api should be very familiarforaiopg user.:

importasyncioimportsqlalchemyassafromaiomysql.saimportcreate_enginemetadata=sa.MetaData()tbl=sa.Table('tbl',metadata,sa.Column('id',sa.Integer,primary_key=True),sa.Column('val',sa.String(255)))asyncdefgo(loop):engine=awaitcreate_engine(user='root',db='test_pymysql',host='127.0.0.1',password='',loop=loop)asyncwithengine.acquire()asconn:awaitconn.execute(tbl.insert().values(val='abc'))awaitconn.execute(tbl.insert().values(val='xyz'))asyncforrowinconn.execute(tbl.select()):print(row.id,row.val)engine.close()awaitengine.wait_closed()loop=asyncio.get_event_loop()loop.run_until_complete(go(loop))

Requirements

About

aiomysql is a library for accessing a MySQL database from the asyncio

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python99.6%
  • Makefile0.4%

[8]ページ先頭

©2009-2025 Movatter.jp