An async wrapper for the sqlite3 module compatible with both asyncio and trio.
Project description
anysqlite3
anysqlite3 is a wrapper around sqlite3 that allows you to interact with SQLite databases from async code.
It is built on top of the built-in sqlite3 module and is compatible with both asyncio and trio code.
Installation
pip install anysqlite3
Usage
anysqlite3 provides essentially the same API as the built-in sqlite3 module, but with async versions of most methods.
import anyio # or asyncio or trio
import anysqlite3
async def main():
async with await anysqlite3.connect(":memory:") as db:
await db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)")
await db.execute("INSERT INTO users (name) VALUES (?)", ("Alice",))
await db.execute("INSERT INTO users (name) VALUES (?)", ("Bob",))
async for row in db.execute("SELECT * FROM users"):
print(row)
anyio.run(main())
Transactions
anysqlite3 provides a context manager for transactions.
Use this instead of the database's commit and rollback methods.
Transactions hold a lock on the database, so you should always use them in a with block.
async with db.transaction() as t:
await db.execute("INSERT INTO users (name) VALUES (?)", ("Charlie",))
await t.rollback()
await db.execute("INSERT INTO users (name) VALUES (?)", ("David",))
await t.commit()
License
This project is licensed under the MIT License - see LICENSE.txt for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anysqlite3-0.0.1.tar.gz.
File metadata
- Download URL: anysqlite3-0.0.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaf18d12acc5420a238df0486e1acfe2cd94d7abd6b4b5a9fa61b43f80d70860
|
|
| MD5 |
f12f5e6723db48d038094d219be0cf8c
|
|
| BLAKE2b-256 |
d860a62ea2bdbd5ca5ef65b121843b1909bfdbf5ac8754ae0cdcfc29930e0599
|
File details
Details for the file anysqlite3-0.0.1-py3-none-any.whl.
File metadata
- Download URL: anysqlite3-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e725cee3db8e487c6534c03f8b9e9174ecca5f2356c5d03086bc19075fb33f17
|
|
| MD5 |
7308ec9e3c29113b4c54c836288626c1
|
|
| BLAKE2b-256 |
6643733a22d891466ebf8f15aaf4bdc0ca4ad62c98db99e0bf127d017da8f7fe
|