Skip to main content

Python (DB-API 2.0) binding for SQLXtraLite — a from-scratch SQL engine in Rust

Project description

sqlxtralite

An embedded SQL database for Python — a single file, no server, no setup. It speaks the familiar DB-API 2.0 interface and returns native Python types (int, float, str, bytes, None).

Install

pip install sqlxtralite

Quick start

import sqlxtralite

con = sqlxtralite.connect("shop.db")          # opens (or creates) one file
cur = con.cursor()

cur.execute("CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT, price REAL)")
cur.execute("INSERT INTO items VALUES (1, 'basil', 2.95)")

cur.execute("SELECT name, price FROM items")
print(cur.fetchall())        # [('basil', 2.95)]
con.close()

Parameters & bulk insert

# qmark (?) placeholders; None -> NULL
cur.execute("INSERT INTO items VALUES (?, ?, ?)", (2, "mint", None))

# insert many rows at once
cur.executemany(
    "INSERT INTO items VALUES (?, ?, ?)",
    [(3, "sage", 4.20), (4, "thyme", 1.50)],
)

cur.execute("SELECT name FROM items WHERE price > ?", (2.0,))
print([row[0] for row in cur.fetchall()])     # ['basil', 'sage']

Fetching results

cur.execute("SELECT id, name FROM items ORDER BY id")

cur.fetchone()      # (1, 'basil')          — next row, or None at the end
cur.fetchmany(2)    # [(2, 'mint'), (3, 'sage')]
cur.fetchall()      # the rest

print([d[0] for d in cur.description])        # column names: ['id', 'name']
print(cur.rowcount, cur.lastrowid)

Queries it supports

# joins, aggregates, grouping
cur.execute("""
    SELECT name, SUM(price) AS total
    FROM items
    GROUP BY name
    HAVING total > 1
    ORDER BY total DESC
""")

# CASE, UNION, subqueries, REPLACE, INSERT ... ON DUPLICATE KEY UPDATE, …
cur.execute("INSERT INTO items VALUES (1, 'basil', 9.99) "
            "ON DUPLICATE KEY UPDATE price = VALUES(price)")

API

connect(path)Connection. Module flags: apilevel = "2.0", paramstyle = "qmark", threadsafety = 1. Errors raise sqlxtralite.Error.

Object Methods / attributes
Connection cursor(), execute(sql, params=None), commit(), rollback(), close(), with support
Cursor execute(sql, params=None), executemany(sql, rows), fetchone(), fetchmany(size=1), fetchall(), description, rowcount, lastrowid, close()

Notes

  • Use one connection per thread.
  • Each statement auto-commits; for multi-statement transactions issue explicit BEGIN / COMMIT with execute.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

sqlxtralite-0.1.1-cp38-abi3-win_amd64.whl (748.5 kB view details)

Uploaded CPython 3.8+Windows x86-64

sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (911.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (866.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

sqlxtralite-0.1.1-cp38-abi3-macosx_11_0_arm64.whl (811.6 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file sqlxtralite-0.1.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: sqlxtralite-0.1.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 748.5 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sqlxtralite-0.1.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a51273337a61f56e85a97a52e4d5eb7946db39b638fee9d31cc67c9269289099
MD5 f16ef10f58c6977dc3ff3e7ce9d11686
BLAKE2b-256 7719b4adb596396a5465c636148e60a4427b1abccbe5ed0a32297e84072628e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.1-cp38-abi3-win_amd64.whl:

Publisher: wheels.yml on parisxmas/SQLXtraLite

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

File details

Details for the file sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2af1229be7aa98fbf605cbec1f6c06b6eca7523827d483c6962af7d0c78d8165
MD5 60afcdfed06b4e8863670cb86d58192d
BLAKE2b-256 c8d44c4cdff7612b5c554fe6ef404eebd0109f5ab974b76cc041b41c9b58e4c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on parisxmas/SQLXtraLite

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

File details

Details for the file sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b0432e486ea0ddf3c898e44e79ddcb725005f08506980083df70a2e71ac8019f
MD5 b3b766249a31d5d8e0dfcb053c00975d
BLAKE2b-256 144211c8bceba3749500aed83063378232f4d808e1501876615fa96202d3b8ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: wheels.yml on parisxmas/SQLXtraLite

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

File details

Details for the file sqlxtralite-0.1.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sqlxtralite-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d08d52940008b6af3c72addfe467472a820f51ab82825356f0d2367cc21e368f
MD5 be9cb910808a00b84b83763fee00dcdf
BLAKE2b-256 45a2042197c28b82f07d8a16cd70d76ed1f9928e163d0593e49a025939c8f993

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.1-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on parisxmas/SQLXtraLite

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