sqlite3-api

2.0.4 · maintenance · verified Tue Apr 14

The `sqlite3-api` library (PyPI package version 2.0.4) provides a thin Pythonic wrapper for interacting with SQLite databases. It simplifies some interactions but appears to be minimally maintained, with its last release in November 2021. Most Python users typically interact with SQLite using the `sqlite3` module from Python's standard library, which offers a comprehensive DB-API 2.0 compliant interface.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection, create a table, insert, query, and update data using the `sqlite3-api` wrapper. It emphasizes explicit commit/rollback for transaction management and closing the connection.

import os
from sqlite3_api import SQL

# Create an in-memory database (for a file-based DB, use 'my_database.db')
db_path = ':memory:' 
conn = SQL(db_path)

try:
    # Create a table
    conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)")

    # Insert data
    conn.execute("INSERT INTO users (name) VALUES (?)", ("Alice",))
    conn.execute("INSERT INTO users (name) VALUES (?)", ("Bob",))
    conn.commit() # Explicitly commit changes

    # Query data
    print("--- All Users ---")
    results = conn.query("SELECT * FROM users")
    for row in results:
        print(row)

    # Update data
    conn.execute("UPDATE users SET name = ? WHERE id = ?", ("Charlie", 1))
    conn.commit() # Explicitly commit changes

    # Verify update
    print("\n--- Updated User 1 ---")
    updated_user = conn.query("SELECT name FROM users WHERE id = 1")
    for row in updated_user:
        print(row)

except Exception as e:
    print(f"An error occurred: {e}")
    conn.rollback() # Rollback on error
finally:
    conn.close() # Always close the connection

view raw JSON →