django-sqlite-strict
django-sqlite-strict is a drop-in replacement for Django's stock SQLite engine that enforces
STRICT tables.
Prerequisites
django-sqlite-strict works on Django webapps that use:
- Django >= 4.2
- SQLite >= 3.37.0
Supported Django versions depend on the Python version in use; see pyproject.toml
for the exact dependency constraints.
Install
-
Add as a dependency:
uv add django-sqlite-strict
-
In
settings.py, add toINSTALLED_APPS.INSTALLED_APPS = [ ..., 'django_sqlite_strict', ..., ]
-
In
settings.py, configure DATABASES to use it as the engine:DATABASES = { "default": { "ENGINE": "django_sqlite_strict", "NAME": BASE_DIR / "db.sqlite3", } }
Features
Compared to Django's stock SQLite backend
SQLite STRICT tables only permit the storage classes INTEGER, REAL, TEXT, BLOB and ANY
(source).
To generate valid STRICT tables, django-sqlite-strict maps field types differently to Django's
stock SQLite backend. For example:
CharFieldis stored asTEXTinstead ofVARCHARBooleanFieldasINTEGERinstead ofBOOLDecimalFieldasREALinstead ofDECIMAL
These field remappings affect only the SQL column types used in migrations. Django's Python field API remains unchanged.
StrictDecimalField
django_sqlite_strict.fields.StrictDecimalField is a DecimalField subclass that stores exact
integer minor units in an INTEGER column instead of storing decimals as REAL. For example,
Decimal("19.99") with decimal_places=2 is stored as 1999 and read back as a Decimal.
from django.db import models
from django_sqlite_strict.fields import StrictDecimalField
class Order(models.Model):
total_price = StrictDecimalField(max_digits=18, decimal_places=2)
- Round-trips are exact for
max_digits <= 18. Thedss.E003check guards against wider fields because they could overflow SQLite's 8-byte INTEGER. - Values with more decimal places than the field declares raise
ValueErroron save. - Lookups and ordering work normally because comparisons are scaled to the stored integer value.
- SQL-side arithmetic, including
F()expressions, and raw SQL use the stored minor units, ie.1999rather than19.99.
System checks
django-sqlite-strict will register the following Django system checks:
check_column_types
Raises an error if any entry in theDATABASESsetting has a column of a type that is not accepted by STRICT tables.check_tables_are_strict
Raises an error if a model's table already exists in the database but is not STRICT, ie. theENGINEwas switched without runningconvert_to_strict.check_decimal_max_digits
Raises a warning if aDecimalFieldhasmax_digitsset to a value higher than the '15 significant digits' threshold up to which SQLite's REAL stores decimals.dss.E003
Raises an error if aStrictDecimalFieldhasmax_digits > 18, meaning its integer minor units could overflow SQLite's 8-byte INTEGER. Runs on every./manage.py check.
Management commands
convert_to_strict
Rebuilds existing non-STRICT tables as STRICT ones. Pass--dry-runto preview the effect of this command, and--no-inputfor use in CI pipelines.
Escape hatches
When you own the model, prefer mapping unsupported field types to STRICT-compatible storage, for
example use StrictDecimalField for exact decimals.
For third-party app models, setting the strict_exempt_tables option allows specified tables to
be created with Django's stock non-STRICT template. Exempt tables are skipped by the checks & the
convert_to_strict management command.
DATABASES = {
"default": {
"ENGINE": "django_sqlite_strict",
"NAME": BASE_DIR / "db.sqlite3",
"OPTIONS": {
"strict_exempt_tables": ["some_third_party_table"],
},
}
}
Develop
Development prerequisites
The following tools must be available locally to develop django-sqlite-strict:
Run tests
The project aims for 100% test coverage. nox is used to run the test suite against
all supported Python/Django pairings (see noxfile.py).
# run latest supported Python/Django pairing only
# (eg. Python 3.14 / Django 6.1)
uvx nox
# run all test sessions
# (ie. all supported Python/Django pairings)
uvx nox -s test
Use the development version in projects
Build the package as a binary distribution (wheel) and install it in a Django project:
# in django-sqlite-strict's root directory
uv build
# in the target Django webapp project
uv add ~/Projects/django-sqlite-strict/dist/django_sqlite_strict-M.m.p-py3-none-any.whl
Acknowledgements
This package was inspired by Martin Dørum's advocacy for STRICT tables in the article SQLite should have (Rust-style) editions.
Shameless self-promotion
Starting a new Django project? Try djereo for a Django project template with modern defaults.
Try pycliché for a no-nonsense Python project template with opinionated tooling.
19th century apparatus to enforce STRICT columns (source, Eton College)
Metadata
Release files for django-sqlite-strict 1.1.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 | Actions |
|---|---|---|---|---|
| django_sqlite_strict-1.1.0.tar.gz | 11.2 kB | Without provenance | Details for django_sqlite_strict-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_sqlite_strict-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_sqlite_strict-1.1.0-py3-none-any.whl |
Total release size: 25.3 kB
Release files / django_sqlite_strict-1.1.0.tar.gz
| Download URL | django_sqlite_strict-1.1.0.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1c8c2fa8e1487e000256390799031409d86ae4d096903b2974ce0d00087644a
|
|
BLAKE2b-256 checksum How to use checksums |
38e84966fe7a78e106c24987c0229a0576ca4c5430504988927c65f1d54aafe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / django_sqlite_strict-1.1.0-py3-none-any.whl
| Download URL | django_sqlite_strict-1.1.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a01b0f4a96dbb7b9e1c2f7b3cc7ca19430201e3fb199de9dee7ebf507e24dd63
|
|
BLAKE2b-256 checksum How to use checksums |
5004967776c2020221bef58093eaf01d3648a4ed0aabf14309c34aaab35ba396
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for django-sqlite-strict 1.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.