APSW Utilities

0.1.2 · active · verified Sun Apr 12

apswutils (version 0.1.2) is a Python utility library that forks sqlite-minutils to provide a convenient API for interacting with SQLite databases using the `apsw` driver. It offers simplified methods for database and table creation, data insertion, and querying, essentially acting as a lightweight wrapper over `apsw`. The project is actively maintained with recent updates and emphasizes features like WAL mode by default.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an in-memory SQLite database, create a table with defined columns and a primary key, insert single and multiple records, and query all rows. It also shows how to modify the table schema by adding a new column.

from apswutils.db import Database, Table

db = Database(':memory:') # Use ':memory:' for an in-memory database

# Create a table
users = Table(db, 'Users')
users.create(columns=dict(id=int, name=str, age=int), pk='id')

# Insert data
users.insert({'id': 1, 'name': 'Alice', 'age': 30})
users.insert_all([
    {'id': 2, 'name': 'Bob', 'age': 24},
    {'id': 3, 'name': 'Charlie', 'age': 35}
])

# Query data
for user in users.rows:
    print(f"ID: {user['id']}, Name: {user['name']}, Age: {user['age']}")

# Update table schema (add a column)
users.create(columns=dict(id=int, name=str, age=int, email=str), transform=True, pk='id')
print("\nUpdated schema:")
print(db.schema)

db.close()

view raw JSON →