Python bindings for SQLRite — a small, embeddable SQLite clone written in Rust.
Project description
sqlrite (Python)
Python bindings for SQLRite — a small, embeddable SQLite clone written in Rust. Shape follows PEP 249 / the stdlib sqlite3 module, so most callers can pick it up without reading the docs.
Install
# From PyPI:
pip install sqlrite
# From source in a clone of the repo:
pip install maturin
cd sdk/python
maturin develop --release
Quick tour
import sqlrite
# File-backed or in-memory (use `":memory:"` to match sqlite3 convention).
conn = sqlrite.connect("foo.sqlrite")
# conn = sqlrite.connect(":memory:")
cur = conn.cursor()
cur.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
cur.execute("INSERT INTO users (name, age) VALUES ('alice', 30)")
cur.execute("INSERT INTO users (name, age) VALUES ('bob', 25)")
cur.execute("SELECT id, name, age FROM users")
for row in cur:
print(row) # (1, 'alice', 30), then (2, 'bob', 25)
# Column metadata (PEP 249 `.description`):
for col in cur.description:
print(col[0]) # 'id', 'name', 'age'
conn.close()
Transactions
with sqlrite.connect("foo.sqlrite") as conn:
cur = conn.cursor()
cur.execute("BEGIN")
cur.execute("INSERT INTO users (name) VALUES ('carol')")
if looks_good:
conn.commit()
else:
conn.rollback()
# The context manager automatically commits on clean exit
# and rolls back on exception, then closes the connection.
Read-only access
conn = sqlrite.connect_read_only("foo.sqlrite")
# Any write raises sqlrite.SQLRiteError. Multiple read-only
# connections on the same file coexist (shared OS lock).
Vector columns + KNN (Phase 7a–7d)
The engine ships with a fixed-dimension VECTOR(N) storage class and three distance functions (vec_distance_l2, vec_distance_cosine, vec_distance_dot). Plain cursor.execute(...) is all you need from Python — values come back as Python lists of floats.
cur.execute("CREATE TABLE docs (id INTEGER PRIMARY KEY, embedding VECTOR(384))")
cur.execute("INSERT INTO docs (id, embedding) VALUES (1, [0.1, 0.2, ..., 0.0])") # 384 floats
cur.execute("""
SELECT id FROM docs
ORDER BY vec_distance_l2(embedding, [0.1, 0.2, ..., 0.0])
LIMIT 10
""")
for row in cur:
print(row)
For larger collections, build an HNSW index — the executor will use it automatically when the WHERE/ORDER BY shape matches:
cur.execute("CREATE INDEX idx_docs_emb ON docs USING hnsw (embedding)")
JSON columns (Phase 7e)
JSON (and JSONB as an alias) columns store text, validated at INSERT/UPDATE time. Read with json_extract / json_type / json_array_length / json_object_keys. Path subset: $, .key, [N], chained.
cur.execute("CREATE TABLE events (id INTEGER PRIMARY KEY, payload JSON)")
cur.execute(
"INSERT INTO events (payload) VALUES "
"('{\"user\": {\"name\": \"alice\"}, \"score\": 42}')"
)
cur.execute(
"SELECT json_extract(payload, '$.user.name'), json_type(payload, '$.score') FROM events"
)
print(cur.fetchall()) # [('alice', 'integer')]
json_object_keysreturns a JSON-array text rather than a table-valued result (set-returning functions aren't supported yet).
Natural-language → SQL (Phase 7g — coming soon)
The Phase 7g.2-7g.8 wave adds a Python-native conn.ask() that wraps the new sqlrite-ask Rust crate via PyO3. Today it's available only from Rust (sqlrite-ask on crates.io); the Python wrapper lands in 7g.4 and will look like:
# 7g.4 preview — not yet released
import sqlrite
conn = sqlrite.connect("foo.sqlrite")
cfg = sqlrite.AskConfig.from_env() # SQLRITE_LLM_API_KEY etc.
resp = conn.ask("How many users are over 30?", cfg)
print(resp.sql) # "SELECT COUNT(*) FROM users WHERE age > 30"
print(resp.explanation) # "Counts users over the age threshold."
# Convenience:
rows = conn.ask_run("How many users are over 30?", cfg).fetchall()
API surface
| Function / Method | Purpose |
|---|---|
sqlrite.connect(db) |
Open or create a file-backed DB (or :memory:) |
sqlrite.connect_read_only(db) |
Open an existing file with a shared lock |
Connection.cursor() |
Returns a new Cursor |
Connection.execute(sql, ...) |
Shortcut for cursor().execute(...) |
Connection.commit() / .rollback() |
Close the current transaction |
Connection.close() |
Drop the connection (releases OS file lock) |
Connection.in_transaction |
bool — inside a BEGIN … COMMIT/ROLLBACK |
Connection.read_only |
bool — opened via connect_read_only |
Cursor.execute(sql, params=None) |
Run one statement |
Cursor.executemany(sql, seq) |
DB-API placeholder (params deferred) |
Cursor.executescript(sql) |
;-separated batch of statements |
Cursor.fetchone() |
Next row as a tuple, or None |
Cursor.fetchmany(size=None) |
Up to size more rows as a list of tuples |
Cursor.fetchall() |
All remaining rows |
Cursor.description |
PEP 249 7-tuples per column (name + Nones) |
Cursor.rowcount |
-1 (not tracked yet — returns as PEP 249 says) |
iter(cursor) |
for row in cursor: … |
sqlrite.SQLRiteError |
All engine failures bubble up as this |
Parameter binding
execute(sql, params) accepts None and empty tuples/lists for DB-API compatibility, but any non-empty params raises TypeError with a clear message — the underlying engine doesn't support prepared-statement parameter binding yet (deferred to Phase 5a.2). For now, inline values into the SQL (with manual escaping).
Running the tests
maturin develop
python -m pytest tests/
How this ships
- PyO3 (
abi3-py38) for the Rust-Python boundary — one wheel works on every CPython 3.8+ release, no per-version rebuild. - maturin as the build backend, emitting standard
.whlfiles that pip can install directly. - Phase 6f's CI publishes abi3-py38 wheels to PyPI for manylinux x86_64/aarch64, macOS aarch64, and Windows x86_64 (plus an sdist) on every release. OIDC trusted publishing — no long-lived PyPI token in the repo.
Status
Phase 5c MVP: ✅ — basic CRUD, transactions, context managers, read-only mode, iteration. Parameter binding, CursorRow namedtuples, and type converters (datetime, Decimal) are natural follow-ups.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlrite-0.1.17.tar.gz.
File metadata
- Download URL: sqlrite-0.1.17.tar.gz
- Upload date:
- Size: 846.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fcf16e420fddbd283eb6e03776369bb8129cd6d8af131bc79e712a5a0dd4877
|
|
| MD5 |
b195f649cf9d581e242829d8535b8310
|
|
| BLAKE2b-256 |
071b40447b8fd9b14436869b79c49c40e7df342738bb61327bc0c8e2f0b047cc
|
Provenance
The following attestation bundles were made for sqlrite-0.1.17.tar.gz:
Publisher:
release.yml on joaoh82/rust_sqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlrite-0.1.17.tar.gz -
Subject digest:
7fcf16e420fddbd283eb6e03776369bb8129cd6d8af131bc79e712a5a0dd4877 - Sigstore transparency entry: 1405525822
- Sigstore integration time:
-
Permalink:
joaoh82/rust_sqlite@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/joaoh82
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlrite-0.1.17-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: sqlrite-0.1.17-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51b5c00c3186c27d0e4261e4ff4616041a312753ed02a8ddc7bf3c446e3f6944
|
|
| MD5 |
4dcd9332e7b5b1c72db51a5a62ef6a92
|
|
| BLAKE2b-256 |
d0822845861ec227e86bd47ae131c07ae9dc12f807b79b5463cfeff05ec65039
|
Provenance
The following attestation bundles were made for sqlrite-0.1.17-cp38-abi3-win_amd64.whl:
Publisher:
release.yml on joaoh82/rust_sqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlrite-0.1.17-cp38-abi3-win_amd64.whl -
Subject digest:
51b5c00c3186c27d0e4261e4ff4616041a312753ed02a8ddc7bf3c446e3f6944 - Sigstore transparency entry: 1405526341
- Sigstore integration time:
-
Permalink:
joaoh82/rust_sqlite@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/joaoh82
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlrite-0.1.17-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: sqlrite-0.1.17-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f58b6613e51d952738c652778259b1f7da73911268fe2ed4891b9c4c432d098
|
|
| MD5 |
2a9cc772d89c19ef995c25b42ab5a94e
|
|
| BLAKE2b-256 |
e007ee37ce7386b7e124f70427d0e93bc47e3b4c642e38724a67c6e19d42ed7c
|
Provenance
The following attestation bundles were made for sqlrite-0.1.17-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on joaoh82/rust_sqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlrite-0.1.17-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
4f58b6613e51d952738c652778259b1f7da73911268fe2ed4891b9c4c432d098 - Sigstore transparency entry: 1405526091
- Sigstore integration time:
-
Permalink:
joaoh82/rust_sqlite@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/joaoh82
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlrite-0.1.17-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: sqlrite-0.1.17-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d49173c193c8778d37211cd0b76bcaa6ef9953cf45165fced8d128e484bf0b2
|
|
| MD5 |
7485f158fd05f5af601f577316592c05
|
|
| BLAKE2b-256 |
5fa0ef49764cfb34327005ec19edb9de0606c2415d13ff1ba65648fd2dcc0aff
|
Provenance
The following attestation bundles were made for sqlrite-0.1.17-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on joaoh82/rust_sqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlrite-0.1.17-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
8d49173c193c8778d37211cd0b76bcaa6ef9953cf45165fced8d128e484bf0b2 - Sigstore transparency entry: 1405526224
- Sigstore integration time:
-
Permalink:
joaoh82/rust_sqlite@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/joaoh82
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlrite-0.1.17-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlrite-0.1.17-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1337a6153b798ee4fb73e96df763df9bc8967b6848b87ef27e615ce41fd4da37
|
|
| MD5 |
01542ef8e34312b4b8b48b7c9a3d5341
|
|
| BLAKE2b-256 |
f812f13c5442dca724d68b89f3b3ce954727646a43ce52fa1cee28d60b2efef8
|
Provenance
The following attestation bundles were made for sqlrite-0.1.17-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on joaoh82/rust_sqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlrite-0.1.17-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
1337a6153b798ee4fb73e96df763df9bc8967b6848b87ef27e615ce41fd4da37 - Sigstore transparency entry: 1405525940
- Sigstore integration time:
-
Permalink:
joaoh82/rust_sqlite@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/joaoh82
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ec1dfa27ab4af91eb2bf37600f13eba643a1c947 -
Trigger Event:
push
-
Statement type: