Skip to main content

Configure SQLite for production use with Django.

Project description

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+.

Installation

  1. Install dj-lite with pip, uv, etc.
pip install dj-lite

OR

uv add dj-lite
  1. In settings.py add the following.
# settings.py

import dj_lite import sqlite_config

DATABASES = {
  "default": sqlite_config(BASE_DIR),
}
  1. That's it! You're all set to go.

What is even happening here

The Django defaults for SQLite are not great for production use. dj-lite tunes SQLite so it can be safely used in production.

Init Command

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 mmap_size=134217728;
PRAGMA journal_size_limit=27103364;
PRAGMA cache_size=2000;

Transaction Mode

According to the Django documentation, SQLite supports three transaction modes: DEFERRED, IMMEDIATE, and EXCLUSIVE. However, 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.

Note: django-tasks requires a transaction mode of EXCLUSIVE for locking purposes.

Inspiration

Developing

Run the tests

  1. uv pip install -e .
  2. uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj_lite-0.1.0.tar.gz (1.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_lite-0.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file dj_lite-0.1.0.tar.gz.

File metadata

  • Download URL: dj_lite-0.1.0.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for dj_lite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c51fee67365e3a1cdb918486cc50c15bce6b61f4fcfc0248afd5185d3d896bf8
MD5 7689ed10381f697816737ab35d7a1acb
BLAKE2b-256 923b40702fa746ae30c0ff586fac28df973769732bc0e75cc3c16301923c3495

See more details on using hashes here.

File details

Details for the file dj_lite-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dj_lite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for dj_lite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81c2875adebbf4358b4aacb043e0632e8a8c0f127f760b8af0f5e9d38ecfdbca
MD5 cba47ca832320df7059e746cb1562e8f
BLAKE2b-256 9638ce61dbff8ba9e92c34a9f1d21118f72daec3aababe070faa36c8d7644ec3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page