Skip to main content

django-sqlite-strict

python >= 3.10 Django >= 4.2 SQLite prek pytest nox coverage GitHub Actions Workflow Status PyPI Version

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

Install

  1. Add as a dependency:

    uv add django-sqlite-strict
    
  2. In settings.py, add to INSTALLED_APPS after any first-party apps and before django.contrib packages.

    INSTALLED_APPS = [
        ...,
        'django_sqlite_strict',
        ...,
    ]
    
  3. 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:

  • CharField is stored as TEXT instead of VARCHAR
  • BooleanField as INTEGER instead of BOOL
  • DecimalField as REAL instead of DECIMAL

These changes affect only the SQL column types used in migrations, Django's Python field API remains unchanged.

[!WARNING] Because of the above STRICT-compliant field type mappings, DecimalField is stored as REAL.
Applications requiring exact decimal arithmetic should consider storing integer minor units or using a database with native DECIMAL support.

System checks

django-sqlite-strict will register the following Django system checks:

  • check_column_types
    Raises an error if any entry in the DATABASES setting has a column of a type that is not accepted by STRICT tables.
  • check_decimal_max_digits
    Raises a warning if a DecimalField has max_digits set to a value higher than the '15 significant digits' threshold up to which SQLite's REAL stores decimals.

Management commands

  • convert_to_strict
    Rebuilds existing non-STRICT tables as STRICT ones. Pass --dry-run to preview the effect of this command, and --no-input for use in CI pipelines.

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)

Download files

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

Source Distribution

django_sqlite_strict-1.0.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

django_sqlite_strict-1.0.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file django_sqlite_strict-1.0.0.tar.gz.

File metadata

  • Download URL: django_sqlite_strict-1.0.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for django_sqlite_strict-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dad79ab477bdaf862e3fd60935e17f6432bd0536dbf42986dccca3648fd948df
MD5 8edb4914346ccf6114d48e1db30bd1e0
BLAKE2b-256 78b2b354b3f07d31390f32e55a63bbe3982019b78d347fb08734a96a07daa403

See more details on using hashes here.

File details

Details for the file django_sqlite_strict-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_sqlite_strict-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for django_sqlite_strict-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 017831e63bbc30f1034150e541591e54e5a12cc71784c5b650d1b4ddecc1f9e8
MD5 731c5edbf32ac719406769b156642826
BLAKE2b-256 ffc52a4bd81326fcd9dd85d592f768e0bb03b2620188f7bbd3aa0143296150aa

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

This release

1.0.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page