Adapters¶
SQLSpec ships adapter packages for each supported database or driver. Each adapter exports a typed config class and a driver implementation.
Quick Example¶
sqlite config¶from sqlspec import SQLSpec
from sqlspec.adapters.sqlite import SqliteConfig
db_path = tmp_path / "driver.sqlite"
spec = SQLSpec()
config = spec.add_config(SqliteConfig(connection_config={"database": str(db_path)}))
with spec.provide_session(config) as session:
session.execute("create table if not exists health (id integer primary key)")
result = session.execute("select count(*) as total from health")
print(result.one())
Adapter Catalog¶
Adapter |
Config Class |
Sync/Async |
|---|---|---|
asyncpg |
|
Async |
psycopg |
|
Sync + Async |
psqlpy |
|
Async |
cockroach (asyncpg) |
|
Async |
cockroach (psycopg) |
|
Sync + Async |
sqlite |
|
Sync |
aiosqlite |
|
Async |
duckdb |
|
Sync |
mysql-connector |
|
Sync + Async |
pymysql |
|
Sync |
asyncmy |
|
Async |
oracledb |
|
Sync + Async |
bigquery |
|
Sync |
spanner |
|
Sync |
adbc |
|
Sync |
Find each config in sqlspec.adapters.<adapter> (for example,
from sqlspec.adapters.asyncpg import AsyncpgConfig).
Example Library¶
Drivers and Querying for per-adapter configuration examples.
Drivers and Querying for execution patterns.