aiosqlite
Async wrapper around the Python sqlite3 module providing an awaitable connection and cursor interface.
Official Documentation ↗v0.20. Check the official docs for the latest API surface.Installation
pip install aiosqliteMethods
No methods match this filter.
Overview
aiosqlite is an async wrapper around Python sqlite3 offering an awaitable connection and cursor interface. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
aiosqlite.connect— Opens an async SQLite connection usable as an async context manager.db.execute— Runs a single SQL statement and returns a cursor for reading results.cursor.fetchall— Fetches all remaining rows from a cursor opened for a select statement.
Example
import aiosqlite
async with aiosqlite.connect('app.db') as db:
await db.execute('CREATE TABLE IF NOT EXISTS t (id INTEGER)')
await db.commit()
Notes
SQLite still serializes writes, so async does not remove write contention. Foreign keys are off per connection and must be enabled explicitly.
Verification
Insert a row, commit, then select it back and confirm the fetched rows contain the inserted value.
Errors
The official API reference declares the following error types:
aiosqlite.Warning(exception,Bases: Exception) — official text: “exception aiosqlite.Warning Bases: Exception” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)aiosqlite.Error(exception,Bases: Exception) — official text: “exception aiosqlite.Error Bases: Exception” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)aiosqlite.DatabaseError(exception,Bases: Error) — official text: “exception aiosqlite.DatabaseError Bases: Error” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)aiosqlite.IntegrityError(exception,Bases: DatabaseError) — official text: “exception aiosqlite.IntegrityError Bases: DatabaseError” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)aiosqlite.ProgrammingError(exception,Bases: DatabaseError) — official text: “exception aiosqlite.ProgrammingError Bases: DatabaseError” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)aiosqlite.OperationalError(exception,Bases: DatabaseError) — official text: “exception aiosqlite.OperationalError Bases: DatabaseError” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)aiosqlite.NotSupportedError(exception,Bases: DatabaseError) — official text: “exception aiosqlite.NotSupportedError Bases: DatabaseError” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)
Security
Official security statements captured from the package documentation:
- 提供 set_authorizer 回调以控制数据库访问(示例用 sqlite3.SQLITE_DENY 拒绝 DROP 操作) — “async set_authorizer(authorizer_callback) Set an authorizer callback to control database access. The authorizer callback is invoked for each SQL statement that is prepared, and controls whether specific operations are permitted. # Deny all DROP operations if action_code == sqlite3.SQLITE_DROP_TA” (source: https://aiosqlite.omnilib.dev/en/stable/api.html, fetched 2026-11-08T09:38:08.940Z)
API reference evidence
Fetched from official sources on 2026-11-08T09:38:08.940Z via WebFetch https://aiosqlite.omnilib.dev/en/stable/api.html.
aiosqlite.connect→ signature from https://aiosqlite.omnilib.dev/en/stable/api.html; official text: “aiosqlite.connect(database, *, iter_chunk_size=64, loop=None, **kwargs) Create and return a connection proxy to the sqlite database. Return type: Connection”db.execute→ signature from https://aiosqlite.omnilib.dev/en/stable/api.html; official text: “execute(sql, parameters=None) Helper to create a cursor and execute the given query. Return type: Cursor”cursor.fetchall→ signature from https://aiosqlite.omnilib.dev/en/stable/api.html; official text: “async fetchall() Fetch all remaining rows. Return type: Iterable[Row]”
FAQ
- Does aiosqlite allow concurrent writes?
- No. SQLite serializes writes, so aiosqlite runs operations on a thread and concurrent writers can still block.
- How do I turn on foreign keys?
- Execute PRAGMA foreign_keys = ON on each connection, since the setting is per connection and default off.
- Why is commit required after writes?
- SQLite autocommit behavior differs by driver; aiosqlite requires an explicit commit to persist changes.
Report a problem with this API docOpens a pre-filled issue on GitHub.