Skip to main content

PEP 249 (DB-API 2.0) compliant interface for dqlite

Project description

dqlite-dbapi

A PEP 249 (DB-API 2.0) driver for dqlite, Canonical's distributed SQLite. If you have used Python's standard sqlite3 module, this will feel familiar — same connect() / cursor() / execute() / fetchone() shape — but it talks to a replicated dqlite cluster over the network instead of a local file.

It comes in two flavors from one package: a synchronous API (dqlitedbapi) and an async API (dqlitedbapi.aio).

Is this the package you want?

Yes, if you want a drop-in-style database driver for dqlite — directly, or under a tool that expects a DB-API 2.0 driver. For SQLAlchemy specifically, use sqlalchemy-dqlite (it builds on this package).

Installation

pip install dqlite-dbapi

Requires Python 3.13+.

Usage

Sync

import dqlitedbapi

conn = dqlitedbapi.connect("localhost:9001")
cur = conn.cursor()
cur.execute("SELECT 1")
print(cur.fetchone())
conn.close()

Async

import asyncio
from dqlitedbapi.aio import aconnect

async def main():
    conn = await aconnect("localhost:9001")
    cur = conn.cursor()
    await cur.execute("SELECT 1")
    print(await cur.fetchone())
    await conn.close()

asyncio.run(main())

Key facts

  • apilevel = "2.0", paramstyle = "qmark" (? placeholders), threadsafety = 2.
  • Autocommit by default. Unlike stdlib sqlite3, the driver does not auto-BEGIN before a statement — wrap writes in an explicit transaction when you need atomic multi-statement semantics. See Transactions.
  • Isolation is always SERIALIZABLE — every write goes through Raft consensus, every read is serializable.

The dqlite Python stack

This is one of four layered packages. Each builds on the one below:

Package Role
sqlalchemy-dqlite SQLAlchemy 2.0 dialect
dqlite-dbapi — this package PEP 249 (DB-API 2.0) driver — sync & async
dqlite-client Async wire client — pooling, leader discovery
dqlite-wire Wire-protocol codec

Using SQLAlchemy or an ORM? Prefer sqlalchemy-dqlite.

Documentation

Development

See DEVELOPMENT.md for setup and contribution guidelines.

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

dqlite_dbapi-0.3.0.tar.gz (439.1 kB view details)

Uploaded Source

Built Distribution

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

dqlite_dbapi-0.3.0-py3-none-any.whl (114.5 kB view details)

Uploaded Python 3

File details

Details for the file dqlite_dbapi-0.3.0.tar.gz.

File metadata

  • Download URL: dqlite_dbapi-0.3.0.tar.gz
  • Upload date:
  • Size: 439.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dqlite_dbapi-0.3.0.tar.gz
Algorithm Hash digest
SHA256 31b02103f450c3a0c4666406ce8eb224a882287f32d3a55c92a6a5701fa8e49f
MD5 9f4cf3b970d77ebf9418f5248bc26064
BLAKE2b-256 daf4c4f52833c0da895c228cd20fc7604c6f2a7ab28399fca6561d1e5cbdefdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for dqlite_dbapi-0.3.0.tar.gz:

Publisher: publish-to-pypi.yml on letsdiscodev/python-dqlite-dbapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dqlite_dbapi-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dqlite_dbapi-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 114.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dqlite_dbapi-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 606b802dfc840f8b599a436cac4085beda6b49857332fe0755e52efaa76a4ae7
MD5 2526ee8c854c5c62da04f7d0e7fab5c5
BLAKE2b-256 5d886d6d21525377871354beb8357f150845ec4c1500ddb7cdf35827e94fbb1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dqlite_dbapi-0.3.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on letsdiscodev/python-dqlite-dbapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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