API Reference¶
Connection¶
- aiosqlite.connect(database, *, iter_chunk_size=64, loop=None, **kwargs)¶
Create and return a connection proxy to the sqlite database.
- Parameters:
- Return type:
- class aiosqlite.Connection(connector, iter_chunk_size, loop=None)¶
Bases:
Thread
- Parameters:
connector (Callable[[], Connection]) –
iter_chunk_size (int) –
loop (AbstractEventLoop | None) –
- async __aenter__()¶
- Return type:
- async __aexit__(exc_type, exc_val, exc_tb)¶
- Return type:
None
- __await__()¶
- Return type:
Generator[Any, None, Connection]
- async backup(target, *, pages=0, progress=None, name='main', sleep=0.25)¶
Make a backup of the current database to the target database.
Takes either a standard sqlite3 or aiosqlite Connection object as the target.
- Parameters:
target (Connection | Connection) –
pages (int) –
name (str) –
sleep (float) –
- Return type:
None
- async close()¶
Complete queued queries/cursors and close the connection.
- Return type:
None
- async commit()¶
Commit the current transaction.
- Return type:
None
- async create_function(name, num_params, func, deterministic=False)¶
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.
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.
- execute(sql, parameters=None)¶
Helper to create a cursor and execute the given query.
- execute_fetchall(sql, parameters=None)¶
Helper to execute a query and return all the data.
- execute_insert(sql, parameters=None)¶
Helper to insert and get the last_insert_rowid.
- executemany(sql, parameters)¶
Helper to create a cursor and execute the given multiquery.
- executescript(sql_script)¶
Helper to create a cursor and execute a user script.
- async interrupt()¶
Interrupt pending queries.
- Return type:
None
- async iterdump()¶
Return an async iterator to dump the database in SQL text format.
Example:
async for line in db.iterdump(): ...
- Return type:
- async rollback()¶
Roll back the current transaction.
- Return type:
None
- async set_progress_handler(handler, n)¶
Cursors¶
- class aiosqlite.cursor.Cursor(conn, cursor)¶
Bases:
object
- Parameters:
conn (Connection) –
cursor (Cursor) –
- async __aenter__()¶
- async __aexit__(exc_type, exc_val, exc_tb)¶
- __aiter__()¶
The cursor proxy is also an async iterator.
- Return type:
- async close()¶
Close the cursor.
- Return type:
None
- async execute(sql, parameters=None)¶
Execute the given query.
- async executemany(sql, parameters)¶
Execute the given multiquery.
- async executescript(sql_script)¶
Execute a user script.
- async fetchmany(size=None)¶
Fetch up to cursor.arraysize number of rows.
- property connection: Connection¶
Errors¶
- 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, callable)¶
Registers an adapter with sqlite3’s adapter registry.
- aiosqlite.register_converter(typename, callable)¶
Registers a converter with sqlite3.