sqlite3-api
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
- gotcha The `sqlite3-api` PyPI package is a separate, third-party wrapper, not the built-in `sqlite3` module that ships with Python. Most Python users interacting with SQLite should use the standard library's `sqlite3` module, which is actively maintained and fully DB-API 2.0 compliant.
- deprecated The `sqlite3-api` package appears to be minimally maintained, with its last release in November 2021. Users seeking active development, community support, or robust features should consider Python's built-in `sqlite3` module or other actively maintained database access layers.
- gotcha While the `sqlite3-api` wrapper might abstract some cursor management, explicit transaction control (e.g., `conn.commit()` and `conn.rollback()`) is still crucial for ensuring data integrity, especially after write operations. Forgetting to commit will result in changes not being saved.
Install
-
pip install sqlite3-api
Imports
- SQL
from sqlite3_api import SQL
Quickstart
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