API Reference¶
Connection¶
- aiosqlite.connect(database: str | Path, *, iter_chunk_size=64, loop: AbstractEventLoop | None = None, **kwargs: Any) Connection ¶
Create and return a connection proxy to the sqlite database.
- class aiosqlite.Connection(connector: Callable[[], Connection], iter_chunk_size: int, loop: AbstractEventLoop | None = None)¶
Bases:
Thread
- async __aenter__() Connection ¶
- async __aexit__(exc_type, exc_val, exc_tb) None ¶
- __await__() Generator[Any, None, Connection] ¶
- async backup(target: Connection | Connection, *, pages: int = 0, progress: Callable[[int, int, int], None] | None = None, name: str = 'main', sleep: float = 0.25) None ¶
Make a backup of the current database to the target database.
Takes either a standard sqlite3 or aiosqlite Connection object as the target.
- async close() None ¶
Complete queued queries/cursors and close the connection.
- async commit() None ¶
Commit the current transaction.
- async create_function(name: str, num_params: int, func: Callable, deterministic: bool = False) None ¶
Create user-defined function that can be later used within SQL statements. Must be run within the same thread that query executions take place so instead of executing directly against the connection, we defer this to run function.
In Python 3.8 and above, if deterministic is true, the created function is marked as deterministic, which allows SQLite to perform additional optimizations. This flag is supported by SQLite 3.8.3 or higher,
NotSupportedError
will be raised if used with older versions.
- async enable_load_extension(value: bool) None ¶
- execute(sql: str, parameters: Iterable[Any] = None) Cursor ¶
Helper to create a cursor and execute the given query.
- execute_fetchall(sql: str, parameters: Iterable[Any] = None) Iterable[Row] ¶
Helper to execute a query and return all the data.
- execute_insert(sql: str, parameters: Iterable[Any] = None) Row | None ¶
Helper to insert and get the last_insert_rowid.
- executemany(sql: str, parameters: Iterable[Iterable[Any]]) Cursor ¶
Helper to create a cursor and execute the given multiquery.
- async interrupt() None ¶
Interrupt pending queries.
- async iterdump() AsyncIterator[str] ¶
Return an async iterator to dump the database in SQL text format.
Example:
async for line in db.iterdump(): ...
- async load_extension(path: str)¶
- async rollback() None ¶
Roll back the current transaction.
- async set_progress_handler(handler: Callable[[], int | None], n: int) None ¶
- async set_trace_callback(handler: Callable) None ¶
- property in_transaction: bool¶
- property isolation_level: str¶
- property row_factory: Type | None¶
- property text_factory: Type¶
- property total_changes: int¶
Cursors¶
- class aiosqlite.cursor.Cursor(conn: Connection, cursor: Cursor)¶
Bases:
object
- async __aenter__()¶
- async __aexit__(exc_type, exc_val, exc_tb)¶
- __aiter__() AsyncIterator[Row] ¶
The cursor proxy is also an async iterator.
- async close() None ¶
Close the cursor.
- async executemany(sql: str, parameters: Iterable[Iterable[Any]]) Cursor ¶
Execute the given multiquery.
- async fetchall() Iterable[Row] ¶
Fetch all remaining rows.
- async fetchmany(size: int = None) Iterable[Row] ¶
Fetch up to cursor.arraysize number of rows.
- async fetchone() Row | None ¶
Fetch a single row.
- property arraysize: int¶
- property connection: Connection¶
- property description: Tuple[Tuple]¶
- property lastrowid: int¶
- property rowcount: int¶
Errors¶
- exception aiosqlite.Warning¶
Bases:
Exception
- exception aiosqlite.Error¶
Bases:
Exception
- exception aiosqlite.IntegrityError¶
Bases:
DatabaseError
- exception aiosqlite.ProgrammingError¶
Bases:
DatabaseError
- exception aiosqlite.OperationalError¶
Bases:
DatabaseError
- exception aiosqlite.NotSupportedError¶
Bases:
DatabaseError
Advanced¶
- aiosqlite.register_adapter(type, adapter, /)¶
Register a function to adapt Python objects to SQLite values.
- aiosqlite.register_converter(typename, converter, /)¶
Register a function to convert SQLite values to Python objects.