Registry / database / pysqlite3

pysqlite3

JSON →
library0.6.0pypypi✓ verified 87d ago

pysqlite3 is a Python library that provides a DB-API 2.0 compliant interface for SQLite 3.x databases. It effectively takes the `sqlite3` module from the Python standard library and packages it separately, often with a more recent, statically compiled SQLite library that includes additional features not always present in system-bundled SQLite versions. The current version is 0.6.0. It offers a self-contained binary distribution (`pysqlite3-binary`) that requires no external dependencies.

pip install pysqlite3-binary
INSTALL
IMPORT
SIG · PYSQLITE3
P
pysqlite3
databasepythonv0.6.0
Install
1.7s avg
Import
10ms
Disk
29MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · 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
4/8 runs
✓ 1.68s
py 3.11
4/8 runs
✓ 1.65s
py 3.12
4/8 runs
✓ 1.56s
py 3.13
4/8 runs
✓ 1.6s
py 3.9
4/8 runs
✓ 1.86s
29MB installed
● package 29MB
Code
Verified usage

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

pysqlite3
import pysqlite3
__import__('pysqlite3'); import sys; sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
While this pattern was once used to 'patch' the standard library's `sqlite3`, it is often unnecessary or can cause issues with newer Python versions and can be fragile. Direct import of `pysqlite3` is the intended usage.

This quickstart demonstrates how to connect to an SQLite database (in-memory in this case) using `pysqlite3`, create a table, insert data with parameter substitution to prevent SQL injection, and query the data. It also includes basic error handling for insertions.

import pysqlite3 # Connect to an in-memory database conn = pysqlite3.connect(':memory:') cursor = conn.cursor() # Create a table cursor.execute(''' CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE NOT NULL ) ''') conn.commit() # Insert data try: cursor.execute("INSERT INTO users (name, email) VALUES (?, ?)", ('Alice', 'alice@example.com')) cursor.execute("INSERT INTO users (name, email) VALUES (?, ?)", ('Bob', 'bob@example.com')) conn.commit() print('Data inserted successfully.') except pysqlite3.IntegrityError as e: print(f'Error inserting data: {e}') conn.rollback() # Query data cursor.execute("SELECT id, name, email FROM users") rows = cursor.fetchall() print('\nUsers:') for row in rows: print(f'ID: {row[0]}, Name: {row[1]}, Email: {row[2]}') # Close the connection conn.close()
Debug
Known issues
gotchaSQLite's transactional model (and thus `pysqlite3`'s) implicitly commits open transactions before Data Definition Language (DDL) statements (e.g., CREATE TABLE, ALTER TABLE, DROP TABLE, VACUUM, PRAGMA). This can lead to unexpected behavior if you expect DDL statements to be part of a larger, explicit transaction that can be rolled back. Ensure you commit or rollback explicitly before DDL if transaction integrity is critical.
fix
Be aware of implicit commits for DDL. If precise transaction control is needed around DDL, ensure preceding DML changes are committed, or the DDL is executed in its own implicit transaction scope.
affects: All versions, inherent to SQLite's behavior; `pysqlite` 2.8.0 changed some DDL commit behavior, but the general principle holds.
gotchaSQLite is designed for single-process access, though it handles concurrent reads well. Concurrent *writes* from multiple processes or threads can lead to 'database is locked' errors or contention. While `pysqlite3` allows specifying a timeout for locks, it does not fundamentally change SQLite's locking model.
fix
Design applications to minimize concurrent writes, or implement retry logic with appropriate timeouts. For high-concurrency write scenarios, consider a different database system or a client-server SQLite solution like LiteFS or rqlite.
affects: All versions, inherent to SQLite's design.
gotchaAlways use parameter substitution (e.g., `?` placeholders) when executing SQL queries with user-provided data, rather than Python string formatting. Failure to do so exposes your application to SQL injection vulnerabilities.
fix
Rewrite queries using parameter substitution: `cursor.execute("INSERT INTO users (name) VALUES (?)", (user_name,))` instead of `cursor.execute(f"INSERT INTO users (name) VALUES ('{user_name}')")`.
affects: All versions.
gotchaImproper application shutdowns, especially during active transactions, can lead to data corruption in SQLite databases. Ensure that all transactions are properly committed or rolled back before the application terminates.
fix
Implement proper transaction management, including `try...except...finally` blocks to ensure `conn.commit()` or `conn.rollback()` are called, and ensure database connections are gracefully closed using `conn.close()` or context managers (`with pysqlite3.connect(...) as conn:`).
affects: All versions, inherent to SQLite.
gotchaThe `pysqlite3-binary` package provides a statically-linked, feature-rich, and up-to-date SQLite. If you install `pysqlite3` without the `-binary` suffix, it attempts to link against your system's `libsqlite3`, which might be older or lack features. Mixing these installations or expecting features only present in the binary version when using the system-linked one can lead to confusion or runtime errors.
fix
Decide whether you need the bundled, latest SQLite features (`pysqlite3-binary`) or wish to use your system's SQLite (`pysqlite3`). Explicitly install the desired package. For a robust and consistent environment, `pysqlite3-binary` is often preferred.
affects: All versions offering both `pysqlite3` and `pysqlite3-binary`.
Upgrade
Version history
0.6.0latest on PyPI · released Jan 5, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
pysqlite3 — pip install pysqlite3 · libregistry