dj-lite 💡
Use SQLite in production with Django
Overview
Simplify deploying and maintaining production Django websites by using SQLite in production. dj-lite helps enable the best performance for SQLite for small to medium-sized projects. It requires Django 5.1+.
I also wrote the definitive guide to using Django SQLite in production which has more details about the actual server setup and operations.
Also read through the official Django SQLite notes for more low-level information.
Installation
- Install
dj-litewithpip,uv,poetry, etc.
pip install dj-lite
OR
uv add dj-lite
- In
settings.pyadd the following.
# settings.py
from dj_lite import sqlite_config
DATABASES = {
"default": sqlite_config(BASE_DIR),
}
- That's it! You're all set to go with the default configuration.
Default configuration
{
"ENGINE": "django.db.backends.sqlite3",
"NAME": Path("db.sqlite3"),
"OPTIONS": {
"transaction_mode": "IMMEDIATE",
"timeout": 5,
"init_command": """PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
PRAGMA temp_store=MEMORY;
PRAGMA mmap_size=134217728;
PRAGMA journal_size_limit=27103364;
PRAGMA cache_size=2000;""",
},
}
Args and Kwargs
The sqlite_config method takes in many arguments to tweak the database settings.
base_dir: Path
The directory where the database file will be stored. Required.
file_name: str
Name of the SQLite database file. Defaults to 'db.sqlite3'.
engine: str
Django database backend to use. Defaults to 'django.db.backends.sqlite3'.
transaction_mode: TransactionMode
The transaction locking behavior. Defaults to 'IMMEDIATE'.
timeout: int
Time in seconds to wait for a database lock before raising an error. Defaults to 5.
init_command: str
Custom SQL command to execute when the database connection is created. If None, will be generated from other parameters.
journal_mode: JournalMode
The journal mode for the database. Defaults to 'WAL'.
synchronous: Synchronous
How aggressively SQLite syncs data to disk. Defaults to 'NORMAL'.
temp_store: TempStore
How to store temporary objects. Defaults to 'MEMORY'.
mmap_size: int
Maximum number of bytes to use for memory-mapped I/O. Defaults to 134217728.
journal_size_limit: int
Maximum size of the journal in bytes. Defaults to 27103364.
cache_size: int
Maximum number of database disk pages to hold in memory. Defaults to 2000.
pragmas: dict
Additional PRAGMA statements to include in the init command. These will override any conflicting settings from other parameters.
What is even happening here?
The Django defaults for SQLite are fine for local dev or running tests, but they are not great for production use -- specifically when there are concurrent reads/writes to the database. dj-lite tunes SQLite so it can be safely used in production.
Pragmas
When SQLite opens a database connection, settings (called pragmas) can be passed in to tune the performance. dj-lite comes with highly tuned defaults for these pragmas.
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
PRAGMA temp_store=MEMORY;
PRAGMA mmap_size=134217728;
PRAGMA journal_size_limit=27103364;
PRAGMA cache_size=2000;
What about the foreign_keys pragma?
You might notice that the SQLite foreign_keys pragma is not included above. That is because it is the one pragma that is always passed in when Django creates a connection to SQLite.
Transaction Mode
According to the Django documentation, SQLite supports three transaction modes: DEFERRED, IMMEDIATE, and EXCLUSIVE -- the default is DEFERRED. However, "[to] make sure your transactions wait until timeout before raising “Database is Locked”, change the transaction mode to IMMEDIATE."
In my experience, using IMMEDIATE has been ok as long as database queries are short.
Inspiration
- Litestack
- Django, SQLite, and the Database is Locked Error
- Gotchas with SQLite in Production
- Django SQLite Production Config
- DjangoCon Europe 2024 | Django, SQLite, and Production
- DjangoCon Europe 2023 | Use SQLite in production
Developing
Run the tests
uv pip install -e .uv run pytest
Metadata
Release files for dj-lite 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dj_lite-1.3.0.tar.gz | 5.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dj_lite-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / dj_lite-1.3.0.tar.gz
| Download URL | dj_lite-1.3.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
188ec328bbf9c3c44f023083390afddefa49056d72df4a760ba020e56a43bac4
|
|
BLAKE2b-256 checksum How to use checksums |
38e928ab1e18e7b66d4f9158db11f4c8ad7fe1654d726ffc6762d13efb435a1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 14, 2025.
Transparency logRelease files / dj_lite-1.3.0-py3-none-any.whl
| Download URL | dj_lite-1.3.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e9500633fa262f817712f81825de305a033db08b262dfa87abdfdd7d82485ae
|
|
BLAKE2b-256 checksum How to use checksums |
f8d56380d66beb1170011ea5b47ddbe1bbf9391d7e68465a07269fb55f710a8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 14, 2025.
Transparency logSecurity for dj-lite 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for dj_lite-1.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 14, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.