API Reference¶
Connection¶
-
aiosqlite.
connect
(database: Union[str, pathlib.Path], *, iter_chunk_size=64, loop: Optional[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], iter_chunk_size: int, loop: Optional[asyncio.events.AbstractEventLoop] = None)¶ 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[aiosqlite.core.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, 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.
-
cursor
() → aiosqlite.cursor.Cursor¶ Create an aiosqlite cursor wrapping a sqlite3 cursor object.
-
async
enable_load_extension
(value: bool) → None¶
-
execute
(sql: str, parameters: Iterable[Any] = None) → aiosqlite.cursor.Cursor¶ Helper to create a cursor and execute the given query.
-
execute_fetchall
(sql: str, parameters: Iterable[Any] = None) → Iterable[sqlite3.Row]¶ Helper to execute a query and return all the data.
-
execute_insert
(sql: str, parameters: Iterable[Any] = None) → Optional[sqlite3.Row]¶ Helper to insert and get the last_insert_rowid.
-
executemany
(sql: str, parameters: Iterable[Iterable[Any]]) → aiosqlite.cursor.Cursor¶ Helper to create a cursor and execute the given multiquery.
-
executescript
(sql_script: str) → aiosqlite.cursor.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
¶
-
async
Cursors¶
-
class
aiosqlite.cursor.
Cursor
(conn: Connection, cursor: sqlite3.Cursor)¶ Bases:
object
-
async
__aenter__
()¶
-
async
__aexit__
(exc_type, exc_val, exc_tb)¶
-
__aiter__
() → AsyncIterator[sqlite3.Row]¶ The cursor proxy is also an async iterator.
-
async
close
() → None¶ Close the cursor.
-
async
execute
(sql: str, parameters: Optional[Iterable[Any]] = None) → aiosqlite.cursor.Cursor¶ Execute the given query.
-
async
executemany
(sql: str, parameters: Iterable[Iterable[Any]]) → aiosqlite.cursor.Cursor¶ Execute the given multiquery.
-
async
executescript
(sql_script: str) → aiosqlite.cursor.Cursor¶ Execute a user script.
-
async
fetchall
() → Iterable[sqlite3.Row]¶ Fetch all remaining rows.
-
async
fetchmany
(size: Optional[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
¶
-
async
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