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.2-cp38-abi3-win_amd64.whl (748.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

sqlxtralite-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (911.9 kB view details)

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

sqlxtralite-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (866.9 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

sqlxtralite-0.1.2-cp38-abi3-macosx_11_0_arm64.whl (812.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: sqlxtralite-0.1.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 748.0 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.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2ad9dd1f9d7d89be2bc5ddcc9f06d6a349fbfe77ab0fec51a2e1c048f3b84d5b
MD5 cc71c4f99abc3541c7a3116346f465b6
BLAKE2b-256 5dd9865f9eead4e4ffe267cd64e753740927a8d264975a70abda8ebf0b3c187a

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.2-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.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sqlxtralite-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2df8ba7c06785d5b8452844a09ed5effb9d061d2cebe486b5138241cdee0efc8
MD5 c1e08e8fd439fd1c337b65c7a6539e7d
BLAKE2b-256 d98dcbf41a2b17f253d23c87a41b1903a7325e5ac9a487d3a7a24a3532246d78

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.2-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.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for sqlxtralite-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ac667c95497edc1943f0bc145876769090af939fb4b0d6ee2916198c46e57ce2
MD5 205b3b31699b8069965884fec92142d3
BLAKE2b-256 c7b414fd8615afd5a2d71c43bfe51d13a00f0c09166668671cd2f4c2ca33c90c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.2-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.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sqlxtralite-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fae99aefab3d7e515146ec775f7fe3c3fb2bedfc71ec9a5f284fc88d5908393e
MD5 cbc1125fee6749646f7eac674ad898a3
BLAKE2b-256 beaf4f8867a8609fc2073ed943717258879d82f5da364bff9d54d55e0989a778

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlxtralite-0.1.2-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