ADBC SQLite Driver
adbc-driver-sqlite provides Python bindings for the Arrow Database Connectivity (ADBC) SQLite driver, offering a DBAPI 2.0 / PEP 249-compatible interface. It allows for Arrow-native access to SQLite databases. The current version is 1.11.0, and the project generally follows a bimonthly release cadence for minor versions.
Warnings
- gotcha When connecting to an in-memory SQLite database by omitting the 'uri' parameter or using ':memory:', all connections will share the same database. To create distinct in-memory databases, use a URI like 'file::memory:?cache=shared' with a unique identifier or explicitly close connections.
- gotcha SQLite's dynamic typing can lead to 'Type Promotion' and potential errors during ADBC's Arrow type inference. The driver infers types from the first batch of rows; subsequent batches attempting to convert to incompatible types will raise an error.
- gotcha Modifying SQLite PRAGMA settings that affect transaction state (e.g., `PRAGMA journal_mode`) may fail if executed within an implicit transaction. The ADBC Python API implicitly wraps statements in transactions.
- gotcha SQLite user-defined functions (UDFs) registered with the underlying `sqlite3` module are not directly accessible through `adbc-driver-sqlite` connections, even if they share the same in-memory database. This is due to how ADBC manages its connection to the SQLite C driver.
- gotcha Loading SQLite extensions requires specific connection options (`adbc.sqlite.load_extension.enabled`, `adbc.sqlite.load_extension.path`, `adbc.sqlite.load_extension.entrypoint`) to be set on the connection *after* the connection is initialized, or by using specific methods on `AdbcSqliteConnection`.
- gotcha The underlying C++ SQLite driver library (`libadbc_driver_sqlite.so` on Linux, `.dylib` on macOS, `.dll` on Windows) must be discoverable by the Python package at runtime. If not installed via system package managers or not in a standard search path, this can cause import or connection errors.
Install
-
pip install adbc-driver-sqlite -
pip install adbc-driver-sqlite adbc-driver-manager pyarrow
Imports
- dbapi
import adbc_driver_sqlite.dbapi
Quickstart
import adbc_driver_sqlite.dbapi
import os
db_uri = os.environ.get('ADBC_SQLITE_URI', 'file::memory:?cache=shared')
with adbc_driver_sqlite.dbapi.connect(uri=db_uri) as conn:
with conn.cursor() as cur:
cur.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER, name TEXT)")
cur.execute("INSERT INTO users (id, name) VALUES (?, ?)", (1, 'Alice'))
cur.execute("INSERT INTO users (id, name) VALUES (?, ?)", (2, 'Bob'))
cur.execute("SELECT * FROM users")
result = cur.fetch_arrow_table()
print(result)