aiosqlite3

sqlite3 support for asyncio.


Keywords
aio, asyncio, sqlite
License
MIT
Install
pip install aiosqlite3==0.3.0

Documentation

aiosqlite3

Travis Build Status codecov pypi

Basic Example

import asyncio
import aiosqlite3

async def test_example(loop):
    conn = await aiosqlite3.connect('sqlite.db', loop=loop)
    cur = await conn.cursor()
    await cur.execute("SELECT 42;")
    r = await cur.fetchall()
    print(r)
    await cur.close()
    await conn.close()

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(test_example(loop))

or async with

import asyncio
import aiosqlite3

async def test_example(loop):
    async with aiosqlite3.connect('sqlite.db', loop=loop) as conn:
        async with conn.cursor() as cur:
            await cur.execute("SELECT 42;")
            r = await cur.fetchall()
            print(r)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(test_example(loop))