Skip to main content

anyio bridge to the standard sqlite3 module

Project description

anyio-sqlite

Python versions PyPI release License

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 await 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 procedurally:

import anyio
import anyio_sqlite

async def main():
    con = await anyio_sqlite.connect("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)

License

Licensed under either of

at your option.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anyio_sqlite-0.1.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anyio_sqlite-0.1.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file anyio_sqlite-0.1.1.tar.gz.

File metadata

  • Download URL: anyio_sqlite-0.1.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for anyio_sqlite-0.1.1.tar.gz
Algorithm Hash digest
SHA256 44f15005ef341f7296a791e1d4d4e4605a57a86a66c5834814f7c09971032e02
MD5 abb23438be0d7eca37e07c9cdd0e2c9a
BLAKE2b-256 3908be162314786f6cf1b58c429a75e26925c874d8b44b251600bed508f4aa5e

See more details on using hashes here.

File details

Details for the file anyio_sqlite-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for anyio_sqlite-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d4455d3b4cf0c9d9caed5e63a0defd9fd72b0f9d3d1b20d9442d1d38c416d21
MD5 174af3b740e000b684b40ed26f126710
BLAKE2b-256 6cfdce2e93a5f1c0c6ad3b9c8b1462d563d86e7ca7ccae8d48dfdfae707a5b03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page