An asynchronous way to connect to an sqlite3 database. Normally, this would block the asyncio event loop and slow down the execution speed of the script. This is because asyncio isn't meant for I/O bound tasks. threading is more efficient for that, which is exactly why this module uses it under the hood.
- A similar syntax to the
sqlite3module in the Standard library - Has
asyncioidioms such asasync for,await, andasync with - Provides all features of the built-in
sqlite3module
Installing asqlite3 should be done through PIP:
$ pip install asqlite3Make sure you have Python version 3.6+ before installing!
Contributions are always encouraged and open.
import asyncio
import asqlite3
conn = asqlite3.connect(':memory:')
async def connection():
async with conn:
await conn.execute("CREATE TABLE table (plate INT)")
await conn.execute("INSERT INTO table VALUES (5)")
# connection is automatically closed
loop = asyncio.get_event_loop()
loop.run_until_complete(connection())import asyncio
import asqlite3
conn = asqlite3.connect(':memory:')
async def cursor():
cur = await conn.cursor()
rows = [i async for i in cur]
return rows
loop = asyncio.get_event_loop()
loop.run_until_complete(cursor())asqlite is currently under the MIT license.