pysqlite3-binary
This library takes the SQLite module from Python 3 and packages it as a separately-installable module. The binary package is statically compiled, which makes it easy to embed the library and ensures a recent SQLite version with many features enabled, such as FTS (Full-Text Search), user-defined window functions, and native backup API. It is currently at version 0.5.4.post2 and is actively maintained.
Warnings
- gotcha To replace the standard library's `sqlite3` module with `pysqlite3` for an entire application (e.g., in a Django project or for other libraries expecting `sqlite3`), you must explicitly swap the modules in `sys.modules` early in your application's startup. Otherwise, `import sqlite3` will still load the built-in version.
- gotcha On newer Python versions (e.g., Python 3.12+), the built-in `sqlite3` module might already include a sufficiently recent SQLite version. In such cases, installing `pysqlite3-binary` might be unnecessary and could potentially lead to confusion if the `sys.modules` swap is not used consistently.
- breaking Early versions (prior to 0.5.1 or 0.6.0, depending on the source) of `pysqlite3-binary` might not have been fully self-contained or provided pre-built wheels for all platforms, requiring manual compilation or system dependencies.
- gotcha If you intend to link against a system SQLite library or a specific custom SQLite build instead of using the self-contained binary, you must install the `pysqlite3` source distribution (not `pysqlite3-binary`) and follow specific build steps (e.g., `python setup.py build_static build` or `pip install pysqlite3 --no-binary pysqlite3`).
Install
-
pip install pysqlite3-binary
Imports
- pysqlite3
import pysqlite3
Quickstart
import pysqlite3
conn = pysqlite3.connect(':memory:')
cursor = conn.cursor()
cursor.execute('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)')
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()
for row in cursor.execute('SELECT * FROM users'):
print(row)
conn.close()