Permalink
Fetching contributors…
Cannot retrieve contributors at this time
142 lines (97 sloc) 3.53 KB

Welcome to aiomysql's documentation!

aiomysql is a library for accessing a :term:`MySQL` database from the asyncio (PEP-3156/tulip) framework. It depends and reuses most parts of :term:`PyMySQL` . aiomysql tries to be like awesome aiopg library and preserve same api, look and feel.

Internally aiomysql is copy of PyMySQL, underlying io calls switched to async, basically yield from and asyncio.coroutine added in proper places. :term:`sqlalchemy` support ported from aiopg.

Features

Basics

aiomysql based on :term:`PyMySQL` , and provides same api, you just need to use yield from conn.f() instead of just call conn.f() for every method.

Properties are unchanged, so conn.prop is correct as well as conn.prop = val.

See example:

import asyncio
import aiomysql

loop = asyncio.get_event_loop()

@asyncio.coroutine
def test_example():
    conn = yield from aiomysql.connect(host='127.0.0.1', port=3306,
                                       user='root', password='', db='mysql',
                                       loop=loop)

    cur = yield from conn.cursor()
    yield from cur.execute("SELECT Host,User FROM user")
    print(cur.description)
    r = yield from cur.fetchall()
    print(r)
    yield from cur.close()
    conn.close()

loop.run_until_complete(test_example())

Installation

pip3 install aiomysql

Note

:mod:`aiomysql` requires :term:`PyMySQL` library.

Also you probably want to use :mod:`aiomysql.sa`.

:mod:`aiomysql.sa` module is optional and requires :term:`sqlalchemy`. You can install sqlalchemy by running:

pip3 install sqlalchemy

Source code

The project is hosted on GitHub

Please feel free to file an issue on bug tracker if you have found a bug or have some suggestion for library improvement.

The library uses Travis for Continious Integration and Coveralls for coverage reports.

Dependencies

Authors and License

The aiomysql package is written by Nikolay Novik, :term:`PyMySQL` and aio-libs contributors. It's MIT licensed (same as PyMySQL).

Feel free to improve this package and send a pull request to GitHub.

Contents:

.. toctree::
   :maxdepth: 2

   connection
   cursors
   pool
   tutorial
   sa
   examples
   glossary
   contributing

Indices and tables