Registry / database / aiosqlite

aiosqlite

JSON →
library0.22.1pypypi✓ verified 44d ago

aiosqlite provides a friendly, async interface to SQLite databases, replicating the standard `sqlite3` module but with asynchronous versions of all connection and cursor methods. It enables interaction with SQLite databases on the main AsyncIO event loop without blocking, utilizing a single, shared thread per connection for query execution. The current version is 0.22.1, and it maintains an active release cadence.

database
pip install aiosqlite
Install & Compatibility
Where this runs
tested against v0.22.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.243s · 17.9MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.6s · import 0.212s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

connect
from aiosqlite import connect
import aiosqlite

This quickstart demonstrates creating a database, defining a table, inserting, querying, updating, and deleting data using `aiosqlite`'s async context managers for connections and cursors. It ensures proper resource management by automatically committing transactions and closing connections.

import asyncio import aiosqlite import os async def main(): db_path = os.environ.get('AIOSQLITE_DB_PATH', 'my_database.db') async with aiosqlite.connect(db_path) as db: # Create a table await db.execute(''' CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER ) ''') await db.commit() # Insert data await db.execute("INSERT INTO users (name, age) VALUES (?, ?)", ("Alice", 30)) await db.execute("INSERT INTO users (name, age) VALUES (?, ?)", ("Bob", 24)) await db.commit() # Query data async with db.execute("SELECT id, name, age FROM users WHERE age > ?", (25,)) as cursor: print("Users older than 25:") async for row in cursor: print(f" ID: {row[0]}, Name: {row[1]}, Age: {row[2]}") # Update data await db.execute("UPDATE users SET age = ? WHERE name = ?", (31, "Alice")) await db.commit() # Delete data await db.execute("DELETE FROM users WHERE name = ?", ("Bob",)) await db.commit() async with db.execute("SELECT COUNT(*) FROM users") as cursor: (count,) = await cursor.fetchone() print(f"Total users remaining: {count}") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
gotchaEncountering 'Database is Locked' errors, especially in concurrent scenarios, is a common SQLite issue. While `aiosqlite` provides an async interface, SQLite itself is a single-file database and can face contention.
fix
Increase the `timeout` parameter when calling `aiosqlite.connect()` to allow SQLite more time to acquire locks (e.g., `aiosqlite.connect('db.db', timeout=10)`). Consider optimizing database schemas, queries, or using a connection pool (`aiosqlitepool`) for high-concurrency applications.
affects: All versions
breakingOlder Python versions are no longer supported. Python 3.7 and 3.8 support was dropped in versions 0.20.0 and 0.21.0 respectively.
fix
Ensure your project runs on Python 3.9 or newer. Upgrade your Python environment if using an older version.
affects: 0.20.0+
breakingWhen used with SQLAlchemy, `aiosqlite` versions 0.22.0 and above changed the internal connection class, which is no longer a daemon thread. This can cause applications to hang on exit if SQLAlchemy's `aiosqlite` dialect doesn't explicitly call `await engine.dispose()` to close connections.
fix
If using SQLAlchemy with `aiosqlite >= 0.22.0`, ensure you explicitly call `await engine.dispose()` at the end of your application's main function to properly close all connections and avoid hanging processes. Alternatively, disable connection pooling by using `NullPool`.
affects: 0.22.0+
Upgrade
Version history
0.22.1latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
41 hits · last 30 days
petalbot
4
seranking-bot
4
mj12bot
3
bytedance
3
node
2
ahrefsbot
2
Amazon
1
amazonbot
1
googlebot
1
Resources