Registry / database / sqlite-anyio

sqlite-anyio

JSON →
library0.2.8pypypi✓ verified 85d ago

sqlite-anyio is an asynchronous client for SQLite databases, built on top of the AnyIO library. It provides an `async`/`await` interface for interacting with SQLite, enabling non-blocking database operations within asynchronous Python applications. The current version is 0.2.8, and it maintains a frequent release cadence, often introducing minor features or bug fixes.

pip install sqlite-anyio
INSTALL
IMPORT
SIG · SQLITE-ANYIO
S
sqlite-anyio
databasepythonv0.2.8
Install
1.9s avg
Import
293ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.8 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.309s · 20.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.9s · import 0.277s · 21MB
18MB installed
● package 18MB
Code
Verified usage

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

Connection
from sqlite_anyio import Connection

This quickstart demonstrates opening an asynchronous connection to an SQLite database, creating a table, inserting data, and querying it using both `Connection.execute` and `Cursor` objects, all within an AnyIO runtime. It also shows proper resource management using async context managers.

import anyio from sqlite_anyio import Connection import os async def main(): db_path = "test.db" async with Connection(db_path) as conn: await conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER, name TEXT)") await conn.execute("INSERT INTO users VALUES (?, ?)", 1, "Alice") await conn.execute("INSERT INTO users VALUES (?, ?)", 2, "Bob") async with conn.cursor() as cur: await cur.execute("SELECT id, name FROM users") rows = await cur.fetchall() print(f"All users: {rows}") await cur.execute("SELECT id, name FROM users WHERE id = ?", 1) row = await cur.fetchone() print(f"User with ID 1: {row}") # Clean up the database file if os.path.exists(db_path): os.remove(db_path) if __name__ == "__main__": anyio.run(main)
Debug
Known issues
breakingThe `Connection.execute()` method in version 0.2.8 and later now returns `self` (the Connection object) instead of a new Cursor object. Prior versions might have returned a Cursor or similar.
fix
If you previously relied on `Connection.execute()` to return a cursor for chaining operations, refactor your code to explicitly use `async with conn.cursor() as cur:` to obtain a cursor and then call `await cur.execute(...)`.
affects: >=0.2.8
gotchaBoth `Connection` and `Cursor` objects are designed to be used as asynchronous context managers (`async with`). Failing to use them as such can lead to unclosed database connections or cursors, potentially causing resource leaks or database locking issues.
fix
Always wrap `Connection` and `Cursor` instantiation in `async with` statements to ensure proper resource management, e.g., `async with Connection("db.db") as conn:` and `async with conn.cursor() as cur:`.
affects: >=0.2.1 (Connection), >=0.2.7 (Cursor)
Errors
Common errors & fixes
RuntimeError: You must use `await` with an async function
Attempting to call an asynchronous method (like `conn.execute` or `cur.fetchone`) without `await` inside an `async` function, or calling an `async` function (like `main`) directly from a synchronous context without an async event loop runner (e.g., `anyio.run`).
fix
Ensure all calls to `sqlite-anyio` methods are preceded by `await` within an `async` function. The top-level `async` function must be executed using `anyio.run()` (or `asyncio.run()` if using asyncio backend).
sqlite3.OperationalError: database is locked
SQLite is a file-based database that has limitations on concurrent write access. This error typically occurs when multiple processes, threads, or even multiple `sqlite-anyio` connections within the same application try to write to the database simultaneously, or if a previous connection was not properly closed.
fix
Design your application to minimize concurrent writes or use a queuing mechanism for write operations. Ensure that `Connection` and `Cursor` objects are always properly closed using `async with` context managers. Consider using WAL (Write-Ahead Logging) journal mode for better concurrency if the underlying SQLite setup supports it, though `sqlite-anyio` abstracts this.
NameError: name 'Connection' is not defined
The `Connection` class was not correctly imported from the `sqlite_anyio` library.
fix
Add the correct import statement: `from sqlite_anyio import Connection` at the top of your Python file.
Upgrade
Version history
0.2.8latest on PyPI · released Mar 2, 2026
Audit
Dependencies
anyiorequiredCore asynchronous backend for non-blocking I/O operations.
Agent activity
19 hits · last 30 days
node
14
Meta
2
OpenAI (training)
1
Resources
sqlite-anyio — pip install sqlite-anyio · libregistry