API Reference

Connection

aiosqlite.connect(database: Union[str, pathlib.Path], *, loop: asyncio.events.AbstractEventLoop = None, **kwargs: Any) → aiosqlite.core.Connection

Create and return a connection proxy to the sqlite database.

class aiosqlite.Connection(connector: Callable[], sqlite3.Connection], loop: asyncio.events.AbstractEventLoop)

Bases: threading.Thread

async __aenter__() → aiosqlite.core.Connection
async __aexit__(exc_type, exc_val, exc_tb)None
__await__() → Generator[Any, None, aiosqlite.core.Connection]
async backup(target: Union[Connection, sqlite3.Connection], *, pages: int = 0, progress: Optional[Callable[[int, int, int], 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)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.

async cursor()aiosqlite.core.Cursor

Create an aiosqlite cursor wrapping a sqlite3 cursor object.

async enable_load_extension(value: bool)None
async execute(sql: str, parameters: Iterable[Any] = None)aiosqlite.core.Cursor

Helper to create a cursor and execute the given query.

async execute_fetchall(sql: str, parameters: Iterable[Any] = None) → Iterable[sqlite3.Row]

Helper to execute a query and return all the data.

async execute_insert(sql: str, parameters: Iterable[Any] = None) → Optional[sqlite3.Row]

Helper to insert and get the last_insert_rowid.

async executemany(sql: str, parameters: Iterable[Iterable[Any]])aiosqlite.core.Cursor

Helper to create a cursor and execute the given multiquery.

async executescript(sql_script: str)aiosqlite.core.Cursor

Helper to create a cursor and execute a user script.

async interrupt()None

Interrupt pending queries.

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[], Optional[int]], n: int)None
async set_trace_callback(handler: Callable)None
property in_transaction
property isolation_level
property row_factory
property text_factory
property total_changes

Cursors

class aiosqlite.core.Cursor(conn: aiosqlite.core.Connection, cursor: sqlite3.Cursor)

Bases: object

async __aenter__()
async __aexit__(exc_type, exc_val, exc_tb)
__aiter__()aiosqlite.core.Cursor

The cursor proxy is also an async iterator.

async __anext__()sqlite3.Row

Use cursor.fetchone() to provide an async iterable.

async close()None

Close the cursor.

async execute(sql: str, parameters: Iterable[Any] = None)aiosqlite.core.Cursor

Execute the given query.

async executemany(sql: str, parameters: Iterable[Iterable[Any]])aiosqlite.core.Cursor

Execute the given multiquery.

async executescript(sql_script: str)aiosqlite.core.Cursor

Execute a user script.

async fetchall() → Iterable[sqlite3.Row]

Fetch all remaining rows.

async fetchmany(size: int = None) → Iterable[sqlite3.Row]

Fetch up to cursor.arraysize number of rows.

async fetchone() → Optional[sqlite3.Row]

Fetch a single row.

property arraysize
property connection
property description
property lastrowid
property rowcount

Errors

exception aiosqlite.Warning

Bases: Exception

exception aiosqlite.Error

Bases: Exception

exception aiosqlite.DatabaseError

Bases: sqlite3.Error

exception aiosqlite.IntegrityError

Bases: sqlite3.DatabaseError

exception aiosqlite.ProgrammingError

Bases: sqlite3.DatabaseError

exception aiosqlite.OperationalError

Bases: sqlite3.DatabaseError

exception aiosqlite.NotSupportedError

Bases: sqlite3.DatabaseError

Advanced

aiosqlite.register_adapter(type, callable)

Registers an adapter with pysqlite’s adapter registry. Non-standard.

aiosqlite.register_converter(typename, callable)

Registers a converter with pysqlite. Non-standard.