aiosqlite Adapter¶
from sqlspec.adapters.aiosqlite import (
AiosqliteAggregateConfig,
AiosqliteCollationConfig,
AiosqliteConfig,
AiosqliteConnectionParams,
AiosqliteConnectionPool,
AiosqliteDriver,
AiosqliteDriverFeatures,
AiosqliteExceptionHandler,
AiosqliteFunctionConfig,
AiosqlitePoolParams,
AiosqliteWindowFunctionConfig,
)
Asynchronous SQLite adapter built on aiosqlite. Inherited execution methods are documented on AsyncDriverAdapterBase. See the SQLite Setup Guide for async pool and shared-cache in-memory URI configuration, and the SQLite Data Dictionary & SQL Catalog.
Configuration & Parameters¶
AiosqliteConfig
¶
Bases: AsyncDatabaseConfig['AiosqliteConnection', AiosqliteConnectionPool, AiosqliteDriver]
Database configuration for AioSQLite engine.
AiosqliteConnectionParams
¶
Bases: TypedDict
TypedDict for aiosqlite connection parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
database |
NotRequired[str | PathLike[str]]
|
Filesystem path, |
timeout |
NotRequired[float]
|
Busy lock wait timeout in seconds passed to |
detect_types |
NotRequired[int]
|
Bitmask of |
isolation_level |
NotRequired[SQLiteIsolationLevel]
|
Implicit transaction begin mode, or |
check_same_thread |
NotRequired[bool]
|
Restrict underlying |
factory |
NotRequired[AiosqliteConnectionFactory | None]
|
Custom |
cached_statements |
NotRequired[int]
|
Number of compiled SQLite VM statements cached per connection. |
query_only |
NotRequired[bool]
|
Enforce read-only queries on every physical connection. |
uri |
NotRequired[bool]
|
Interpret |
iter_chunk_size |
NotRequired[int]
|
Row batch size fetched per worker-thread hop when iterating |
autocommit |
NotRequired[SQLiteAutocommitMode]
|
PEP 249 / Python 3.12+ autocommit flag or |
AiosqlitePoolParams
¶
Bases: AiosqliteConnectionParams
TypedDict for aiosqlite pool parameters, inheriting connection parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
pool_size |
NotRequired[int]
|
Maximum number of worker-backed SQLite connections managed by |
min_size |
NotRequired[int]
|
Minimum number of warm connections pre-opened in the pool. |
connect_timeout |
NotRequired[float]
|
Maximum wait time in seconds when acquiring a connection from the pool. |
idle_timeout |
NotRequired[float]
|
Idle duration in seconds before recycling unused pooled connections. |
operation_timeout |
NotRequired[float]
|
Maximum duration in seconds allowed for pool lifecycle operations. |
health_check_interval |
NotRequired[float]
|
Interval in seconds between background or checkout connection health checks. |
enable_optimizations |
NotRequired[bool]
|
Apply WAL journal mode, |
enable_foreign_keys |
NotRequired[bool]
|
Execute |
extra |
NotRequired[dict[str, Any]]
|
Additional keyword arguments forwarded directly to |
AiosqliteDriverFeatures
¶
Bases: TypedDict
Optional aiosqlite driver feature flags, UDF registrations, PRAGMAs, and async hooks.
Attributes:
| Name | Type | Description |
|---|---|---|
enable_custom_adapters |
NotRequired[bool]
|
Register global |
json_serializer |
NotRequired[Callable[[Any], str]]
|
Custom JSON serializer used for bound parameters (defaults to |
json_deserializer |
NotRequired[Callable[[str], Any]]
|
Custom JSON deserializer used for JSON column decoding (defaults to |
reset_session_on_release |
NotRequired[bool]
|
Drop temp objects, detach databases, and restore baseline PRAGMAs when a connection is released (defaults to |
on_connection_create |
NotRequired[Callable[[AiosqliteConnection], Awaitable[None]]]
|
Async hook invoked with each |
enable_events |
NotRequired[bool]
|
Enable durable table-backed SQLSpec event queue support. |
events_backend |
NotRequired[Literal['poll_queue']]
|
Event channel backend ( |
custom_functions |
NotRequired[Sequence[AiosqliteFunctionConfig]]
|
Scalar SQL functions registered on the |
custom_collations |
NotRequired[Sequence[AiosqliteCollationConfig]]
|
Custom SQL collations registered on the |
custom_aggregates |
NotRequired[Sequence[AiosqliteAggregateConfig]]
|
Custom SQL aggregate classes registered on each connection. |
custom_window_functions |
NotRequired[Sequence[AiosqliteWindowFunctionConfig]]
|
Custom SQL window function classes registered on each connection. |
default_transaction_mode |
NotRequired[Literal['DEFERRED', 'IMMEDIATE', 'EXCLUSIVE']]
|
Default |
authorizer_callback |
NotRequired[Callable[[int, str | None, str | None, str | None, str | None], int]]
|
SQLite compile-time authorizer callback executed on the worker thread. |
trace_callback |
NotRequired[Callable[[str], None]]
|
Statement trace callback executed on the worker thread. |
progress_handler |
NotRequired[Callable[[], int | None]]
|
SQLite VM progress hook invoked every |
progress_handler_interval |
NotRequired[int]
|
Positive VM opcode count between |
row_factory |
NotRequired[Literal['row', 'dict', 'tuple'] | Callable[..., Any]]
|
Raw connection row factory selector ( |
text_factory |
NotRequired[Callable[[bytes], Any]]
|
Decoder callable assigned to |
pragmas |
NotRequired[Mapping[str, str | int | bool]]
|
Additional |
extensions |
NotRequired[Sequence[str]]
|
Shared-library SQLite extension paths loaded on each connection. |
AiosqliteFunctionConfig
¶
Bases: TypedDict
User-defined aiosqlite function registration.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
SQL scalar function name registered on the worker-thread SQLite connection. |
narg |
int
|
Expected positional argument count (use |
func |
Callable[..., Any]
|
Synchronous Python callable executed on the |
deterministic |
NotRequired[bool]
|
Mark the function deterministic so SQLite can inline it in indexes and expressions. |
AiosqliteCollationConfig
¶
Bases: TypedDict
User-defined aiosqlite collation registration.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
SQL collation name usable in |
func |
Callable[[str, str], int]
|
Synchronous comparator callable returning negative, zero, or positive ordering. |
AiosqliteAggregateConfig
¶
Bases: TypedDict
User-defined aiosqlite aggregate registration.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
SQL aggregate function name registered on each connection. |
narg |
int
|
Expected argument count passed to |
aggregate_class |
type[Any]
|
Class implementing |
AiosqliteWindowFunctionConfig
¶
Bases: TypedDict
User-defined aiosqlite window function registration.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
SQL window function name registered on each connection. |
narg |
int
|
Expected argument count passed to |
window_class |
type[Any]
|
Class implementing |
Driver, Pool & Data Dictionary¶
AiosqliteDriver
¶
AiosqliteExceptionHandler
¶
Bases: BaseAsyncExceptionHandler
Async context manager for handling aiosqlite database exceptions.
Maps SQLite extended result codes to SQLSpec exceptions stored on
pending_exception.
AiosqliteConnectionPool
¶
Multi-connection pool for aiosqlite.
AiosqliteDataDictionary
¶
Extension Stores & Configs¶
AiosqliteLitestarConfig
¶
Bases: LitestarConfig
Aiosqlite-specific Litestar settings.
Use inside extension_config["litestar"] with this adapter's session store.
Attributes:
| Name | Type | Description |
|---|---|---|
pragma_profile |
NotRequired[bool]
|
Apply the extension-store PRAGMA profile. Default: False. |
pragma_overrides |
NotRequired[dict[str, str | int | bool]]
|
Validated PRAGMA overrides applied during schema preparation. |
AiosqliteStore
¶
Bases: BaseSQLSpecStore['AiosqliteConfig']
SQLite session store using AioSQLite driver.
Implements server-side session storage for Litestar using SQLite via the AioSQLite driver. Provides efficient session management with: - Native async SQLite operations - INSERT OR REPLACE for UPSERT functionality - Automatic expiration handling - Efficient cleanup of expired sessions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AiosqliteConfig
|
AiosqliteConfig instance. |
required |
AiosqliteADKConfig
¶
Bases: ADKConfig
Aiosqlite-specific ADK extension settings.
Use these keys inside extension_config["adk"] with aiosqlite ADK stores.
Attributes:
| Name | Type | Description |
|---|---|---|
pragma_overrides |
NotRequired[Mapping[str, str | int | bool]]
|
Additional validated PRAGMA settings applied after the built-in ADK profile. |
fts_tokenize |
NotRequired[str]
|
Optional FTS5 tokenizer spec used when |
fts_detail |
NotRequired[Literal['full', 'column', 'none']]
|
Optional FTS5 detail mode used when |
AiosqliteADKStore
¶
Bases: BaseAsyncADKStore['AiosqliteConfig']
Aiosqlite ADK store using asynchronous SQLite driver.
Implements session and event storage for Google Agent Development Kit using SQLite via the asynchronous aiosqlite driver.
Provides
- Session state management with JSON storage (as TEXT)
- Event history tracking with full-event JSON storage
- Julian Day timestamps (REAL) for efficient date operations
- Foreign key constraints with cascade delete
- Atomic event+state writes via append_event_and_update_state
- PRAGMA optimization profile for file-based databases
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AiosqliteConfig
|
AiosqliteConfig with extension_config["adk"] settings. |
required |
AiosqliteADKMemoryStore
¶
Bases: BaseAsyncADKMemoryStore['AiosqliteConfig']
Aiosqlite ADK memory store using asynchronous SQLite driver.
Implements memory entry storage for Google Agent Development Kit using SQLite via the asynchronous aiosqlite driver. Provides: - Session memory storage with JSON as TEXT - Simple LIKE search (simple strategy) - Optional FTS5 full-text search (sqlite_fts5 strategy) - Julian Day timestamps (REAL) for efficient date operations - Deduplication via (app_name, user_id, event_id) unique constraint - Efficient upserts using INSERT OR IGNORE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AiosqliteConfig
|
AiosqliteConfig with extension_config["adk"] settings. |
required |
AiosqliteEventsConfig
¶
Bases: EventsConfig
Aiosqlite events settings for queue storage and supported native transports.
Attributes:
| Name | Type | Description |
|---|---|---|
pragma_profile |
NotRequired[bool]
|
Apply the SQLite extension-store PRAGMA profile. Default: False. |
pragma_overrides |
NotRequired[dict[str, str | int | bool]]
|
Validated SQLite PRAGMA overrides applied after the optional profile. |
AiosqliteEventQueueStore
¶
Bases: BaseEventQueueStore[AiosqliteConfig]
Provide column definitions for the async SQLite adapter.
SQLite stores JSON as TEXT since it lacks a native JSON column type. JSON functions can still operate on TEXT columns containing valid JSON.