Registry / database / fastlite

fastlite

JSON →
library0.2.4pypypi✓ verified 24d ago

Fastlite provides quality-of-life improvements for interactive use of the `sqlite-utils` library, particularly in Jupyter environments. It enhances database and table access with auto-completion, simplifies dataclass creation from schemas, and streamlines data manipulation. The library is currently active, with version 0.2.4 addressing recent bug fixes and continuing to evolve with new usability features.

pip install fastlite
INSTALL
IMPORT
SIG · FASTLITE
F
fastlite
databasepythonv0.2.4
Install
2.5s avg
Import
744ms
Disk
27MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 2.7s
py 3.11
✓ —
✓ 2.6s
py 3.12
✓ —
✓ 2.2s
py 3.13
✓ —
✓ 2.4s
py 3.9
✕ build_error
✕ build_error
27MB installed
● package 27MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

*
from fastlite import *
Commonly used to import all Fastlite utilities, including the `database` function.
database
from fastlite import database
Specifically imports the function to create or connect to a SQLite database.

This quickstart demonstrates how to initialize an in-memory SQLite database, create a table with a primary key, insert new records, and retrieve data. It covers basic table creation, insertion, and querying using Fastlite's simplified `db.t` table access.

from fastlite import database import os # Create an in-memory database for quick testing db = database(':memory:') # Or, for a persistent file-based database # db_file = 'example.db' # if os.path.exists(db_file): os.remove(db_file) # Clean up for repeatable example # db = database(db_file) # Create a table named 'users' users_table = db.t.users users_table.create( id=int, name=str, email=str, pk='id' # Set 'id' as the primary key ) # Insert data into the 'users' table users_table.insert({'id': 1, 'name': 'Alice', 'email': 'alice@example.com'}) users_table.insert({'id': 2, 'name': 'Bob', 'email': 'bob@example.com'}) # Query all users print('All users:') for user in users_table(): print(user) # Query a specific user by primary key alice = users_table.get(1) print(f'\nUser with ID 1: {alice}') # Update a user users_table.update({'id': 1, 'name': 'Alicia'}) print('\nUpdated user with ID 1:') for user in users_table(id=1): print(user)
Debug
Known issues
breakingIn version 0.2.0, the `table.fetchone` method was renamed to `table.selectone`. Additionally, `selectone` now strictly raises an exception (`fastlite.core.RowCountError`) if the query returns more than one row, ensuring uniqueness.
fix
Migrate calls from `fetchone` to `selectone`. If your code expects multiple rows or handles non-unique results, adjust logic to catch `RowCountError` or use alternative querying methods like `table()` for a list of results.
affects: >=0.2.0
breakingStarting with versions 0.1.0/0.1.1, Fastlite was rewritten to use `apsw` instead of Python's standard `sqlite3` module. This change was primarily driven by concurrency and performance issues found in `sqlite3` (especially with Python 3.12).
fix
Ensure `apsw` is installed (`pip install apsw`). Code that directly interacted with `sqlite3` specifics or relied on its exact concurrency model might need review, although Fastlite aims to abstract most of these differences.
affects: >=0.1.0
gotchaFastlite maintains a strict distinction between `None` (representing SQL `NULL`) and an empty string (`''`) when interacting with SQLite. This differs from some ORMs that might treat them interchangeably.
fix
When querying or inserting, be mindful of this distinction. Use `WHERE column IS NULL` for `None` values and `WHERE column = ''` for empty strings in SQL queries, and ensure your Python data correctly reflects this semantic difference.
affects: All versions
gotchaWhen using `insert` with `ignore=True` and a duplicate primary key exists, older versions (<0.2.4) could raise a `KeyError` instead of ignoring the insertion.
fix
Upgrade to version 0.2.4 or newer to ensure `insert(..., ignore=True)` behaves as expected and gracefully handles duplicate keys without raising a `KeyError`.
affects: <0.2.4
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fastlite'
The fastlite library, or a dependency that relies on it, has not been installed in your Python environment.
fix
Run `pip install fastlite` to install the library.
AttributeError: 'View' object has no attribute 'xtra'
The `.xtra()` method is designed for filtering `Table` objects in fastlite, but it is not available for `View` objects.
fix
When working with views, use direct SQL queries or standard Pythonic filtering on the results instead of the `.xtra()` method.
fastlite.core.RowCountError: Query returned more than one row but 'selectone' expects exactly one.
The `table.selectone()` method, introduced in fastlite 0.2.0, strictly expects a query to return exactly one row and raises this error if multiple rows are found.
fix
If your query might return multiple rows, use `table()` to retrieve a list of results, or adjust your query to ensure it returns at most one row.
KeyError: ... (when using insert with ignore=True)
In versions of fastlite prior to 0.2.4, using `insert(..., ignore=True)` with a duplicate primary key could unexpectedly raise a `KeyError` instead of ignoring the insertion.
fix
Upgrade fastlite to version 0.2.4 or newer by running `pip install --upgrade fastlite` to ensure `insert(..., ignore=True)` handles duplicate keys gracefully.
Upgrade
Version history
0.2.4latest on PyPI · released Jan 12, 2026
Audit
Dependencies
apswrequiredCore database driver, switched from `sqlite3` for performance and concurrency improvements.
sqlite-utilsrequiredProvides the underlying utility functions that Fastlite builds upon.
fastcoreoptionalOften used in the Fastlite ecosystem for utility functions and interactive development, though not a strict core dependency for basic functionality.
Agent activity
16 hits · last 30 days
node
14
Resources
fastlite — pip install fastlite · libregistry