Skip to main content

Asynchronous driver for sqlite3.

Project description

asyncsqlite3 - asynchronous driver for sqlite3.

Asynchronous interface with context managers for sqlite database:

async with asyncsqlite3.connect(...) as conn:
    async with conn.execute("INSERT INTO some_table ..."):
        await conn.commit()

    async with conn.execute("SELECT * FROM some_table") as cursor:
        rows = await cursor.fetchall()

And without context managers:

conn = await asyncsqlite3.connect(...)
cursor = await conn.execute("SELECT * FROM some_table")
rows = await cursor.fetchall()
await cursor.close()
await conn.close()

Connection pool and transaction:

async with asyncsqlite3.create_pool(..., min_size=1, max_size=2) as pool:
    async with pool.acquire(timeout=1.5) as conn: # You can use a timeout when getting a connection from queue.
        async with conn.transaction():
            async with conn.execute("INSERT INTO some_table ..."):
                ...
    
    async with pool.acquire() as conn:
        async with conn.execute("SELECT id, name FROM some_table") as cursor:
            async for row in cursor:
                print(row) # <Record id=1 name='alex'>
                print(row[0], row["id"], row.get("id")) # 1 1 1
                print(dict(row)) # {'id': 1, 'name': 'alex'}
                print(tuple(row), list(row), set(row)) # (1, 'alex') [1, 'alex'] {1, 'alex'}

Installation

asyncsqlite3 is compatible with Python 3.7 and newer. Use pip to install:

$ pip install asyncsqlite3

You can speed up asyncsqlite3 as follows:

$ pip install asyncsqlite3[uvloop]

Details

How you see this module very look like aiosqlite and asyncpg.

Implicit transactions are turned off, but you can use Connection method transaction.

License

MIT

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

asyncsqlite3-0.1.4.tar.gz (11.7 kB view details)

Uploaded Source

File details

Details for the file asyncsqlite3-0.1.4.tar.gz.

File metadata

  • Download URL: asyncsqlite3-0.1.4.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0a0

File hashes

Hashes for asyncsqlite3-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c71fbf97a0b220752fac4b2c621749f85d5db99fb87e277c44eae9a14b5e1999
MD5 ea11345ea622c990e7f45b234b3c1b0e
BLAKE2b-256 0b286cf53e8932d78d1ad15a579b2dae98e9eba20b3866a394d7eef0c0e22660

See more details on using hashes here.

Supported by

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