anyio-sqlite
anyio-sqlite is an AnyIO bridge to the standard sqlite3 database module, providing
async versions of all connection, cursor and blob (Python 3.11+) methods that runs
on both asyncio and Trio.
Asynchronous context management is also supported.
Install
anyio-sqlite is compatible with Python 3.9 and newer. Install it from PyPI:
pip install anyio-sqlite
Examples
Use it the same way as the standard sqlite3 module, simply scatter the await keyword when needed:
import anyio
import anyio_sqlite
async def main():
async with anyio_sqlite.connect("example.sqlite3") as con:
async with await con.cursor() as cur:
await cur.execute("CREATE TABLE movie(title, year, score)")
await cur.execute("""
INSERT INTO movie VALUES
('Monty Python and the Holy Grail', 1975, 8.2),
('And Now for Something Completely Different', 1971, 7.5)
""")
await con.commit()
async with await con.execute("SELECT score FROM movie") as cur:
async for row in cur:
...
anyio.run(main)
It can also be used mostly procedurally, if you provide an external task group:
import anyio
import anyio_sqlite
async def main():
async with anyio.create_task_group() as tg:
con = await anyio_sqlite.Connection.connect(tg, "example.sqlite3")
cur = await con.cursor()
await cur.execute("CREATE TABLE movie(title, year, score)")
await cur.execute("""
INSERT INTO movie VALUES
('Monty Python and the Holy Grail', 1975, 8.2),
('And Now for Something Completely Different', 1971, 7.5)
""")
await con.commit()
await cur.aclose()
cur = await con.execute("SELECT score FROM movie")
async for row in cur:
...
await cur.aclose()
await con.aclose()
anyio.run(main)
[!WARNING] Since each connection spawns a long-running worker in another thread, the connection must be closed after you're done using it! Otherwise, the process will hang indefinitely waiting for the worker thread to finish.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Release files for anyio-sqlite 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| anyio_sqlite-0.3.0.tar.gz | 16.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| anyio_sqlite-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.7 kB
Release files / anyio_sqlite-0.3.0.tar.gz
| Download URL | anyio_sqlite-0.3.0.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7723e2eb43cdf2be5e02f2db2fe5379523c0af1a3b545b6ef9082faf268d00c
|
|
BLAKE2b-256 checksum How to use checksums |
7b0a7ea29a837f877d8473f4f8a116bd5528fa0034c01cd8fb6d548fdf656f75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / anyio_sqlite-0.3.0-py3-none-any.whl
| Download URL | anyio_sqlite-0.3.0-py3-none-any.whl |
|---|---|
| Size | 19.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
532a2f6103972d13e65a1f54737df3c95d96f38d9e0800669dcf858a9010e4c3
|
|
BLAKE2b-256 checksum How to use checksums |
c87bcb4da545e2f550480c9764f9e9122cf2139a911f002ab09d002d29df522f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|