sqlcipher3 provides a DB-API 2.0 compatible interface for SQLCipher 4.x, allowing encrypted SQLite databases. It wraps SQLCipher's C library and supports transparent 256-bit AES encryption of database files. Current version 0.6.2, requires Python >=3.9. Pre-built wheels available for many platforms; on some systems you may need to compile from source.
pip install sqlcipher3Verified import paths — ran on the pinned version, not inferred.
Create an in-memory encrypted database. PRAGMA key must be set before any other operations.
Ensure SQLCipher 4.x is installed (system library). Use `sqlcipher3-binary` if you cannot compile.
Call `PRAGMA key='your_key'` as first operation after `connect()`. For an existing DB, the key must match.
Set all PRAGMAs immediately after opening the connection, before any CREATE/INSERT/UPDATE.
Install libsqlcipher (e.g., `apt install libsqlcipher-dev` on Debian/Ubuntu, `brew install sqlcipher` on macOS) or use `sqlcipher3-binary` which bundles the library.
Ensure you call `PRAGMA key='...'` immediately after connecting. If opening an existing encrypted database, make sure the key matches the one used when it was created.
Move all PRAGMA cipher settings (key, cipher_page_size, etc.) to immediately after `connect()`, before any other database operations.