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-anyioVerified import paths — ran on the pinned version, not inferred.
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.
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(...)`.
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:`.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).
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.
Add the correct import statement: `from sqlite_anyio import Connection` at the top of your Python file.