API Reference

aiosqlite

Async wrapper around the Python sqlite3 module providing an awaitable connection and cursor interface.

Official Documentation ↗
CompatibilityThis documentation covers version v0.20. Check the official docs for the latest API surface.

Installation

pippip install aiosqlite

Methods

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:

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.

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.