Skip to main content

SQLite database engine for Django that makes every table a STRICT table.

Project description

django-sqlite-strict

python >= 3.10 Django 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.

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.0)
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:

# from 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)

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

django_sqlite_strict-0.3.0.tar.gz (6.7 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-0.3.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_sqlite_strict-0.3.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c66ac7527f42b5195094f27d3429ab38428e7e94d9c29017cd703d091adf9b22
MD5 eaa462769a1e48cee09fa12ac5f48e42
BLAKE2b-256 6e7d2022bec5f225a5ea6ed505add6c326021d6bf25d528d1d89ec3891df0e4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_sqlite_strict-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08e09c12fad1c1bb6aa0e34861fb9a248b5ea4d264e6feacb6e2354fb74554c6
MD5 29f7f1d15792b408fd677bd058891f0a
BLAKE2b-256 ea0a62955ef7da8a194d843f9dbe6d44787782314394fb018b6be7252a499926

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