Check your Django settings for common issues.
Project description
dj-typed-settings
Type checking and IDE autocomplete for Django settings to improve the developer experience.
Installation
uv add dj-typed-settings
OR
pip install dj-typed-settings
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...,
"dj_typed_settings", # required for runtime type checking
]
Features
There are multiple features to help you write better Django settings. they are all optional and opt-in, so you can use as much or as little as you want.
Runtime type checking
Ensures your settings.py values match the expected types (e.g., DEBUG must be bool, TEMPLATES must be list). Also catches typos and invalid keys in complex settings like DATABASES, CACHES, and TEMPLATES.
This will run a system checks when you run python manage.py runserver or python manage.py check and raise an error if any setting is the incorrect type.
To skip, runtime type checking altogether, remove `"dj_typed_settings"` from `INSTALLED_APPS`.
To skip particular settings, add them to `TYPED_SETTINGS_IGNORE_ERRORS` as detailed in the [Configuration](#configuration) section.
Autocomplete when editing settings
Provides IDE autocomplete when editing settings.py.
# settings.py
from dj_typed_settings.defaults import * # noqa: F403
DEBUG = True # IDE autocomplete works here when hovering over "DEBUG"
The * import uses default values from Django's global_settings.py (with additional generated types and docstrings) as the base and allows you to override them. This provides the IDE the information needed to give you autocomplete in the editor.
Typed dictionaries
There are a number of complex settings that are normally dictionaries. dj-typed-settings provides helper methods that mimic the structure of the dictionary, but provide a better autocomplete experience.
# settings.py
from dj_typed_settings import DATABASES
DATABASES = {
"default": DATABASE(
ENGINE="django.db.backends.sqlite3",
NAME="db.sqlite3",
)
}
The available methods are:
AUTH_PASSWORD_VALIDATORCACHEDATABASETEMPLATE
Autocomplete when using settings
Provides IDE autocomplete when using settings in other Python code.
# views.py
from dj_typed_settings.conf import settings
def index(request):
if settings.DEBUG: # Autocomplete in the IDE works here
return HttpResponse("debug")
return HttpResponse("production")
This is a drop-in replacement for from django.conf import settings which provides type hints to the IDE for standard Django settings.
For third-party or custom settings, it works exactly like `django.conf.settings`, i.e. provides no additional type hints. However, it will still return the setting as expected.
Automatically fix setting variable types
dj-typed-settings can also automatically fix up setting variable types. This can be helpful when using the standard library os.getenv() which always returns a string.
# settings.py
from os import getenv
from dj_typed_settings import fixup_types
DEBUG = getenv("DEBUG")
...
fixup_types(globals()) # this will fix up all variables when called at the end of the file
fixup_types() converts all default Django setting variables to the expected type when possible. Supported types:
boolfrom"True","true","False","false","1","0"intfrom"123"floatfrom"123.45"listfrom"1,2,3"(comma separated)
Configuration
You can ignore specific validation errors in your settings.py:
TYPED_SETTINGS_IGNORE_ERRORS = [
"DEBUG", # Ignore type errors for DEBUG
"DATABASES.default.ENGINE", # Ignore specific nested key
]
Goals
- Stay as close to "normal" Django settings.py usage as possible
- No dependencies outside of the Python standard library
- No runtime performance impact (other than the optional system check)
Acknowledgments
There are a lot of Django settings libraries. Here are a few I use or looked at recently:
- django-configurations
- Dynaconf
- python-decouple
- dj-settings
- django-typed-settings
- django-settings-json
- normalized-django-settings
There are also a lot of libraries which get settings from the environment, which is a slightly different use case, but is related.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dj_typed_settings-0.2.0.tar.gz.
File metadata
- Download URL: dj_typed_settings-0.2.0.tar.gz
- Upload date:
- Size: 55.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec380de903cf29bf48e917335dc259a41d6f49c72fe6994333efc622c590200f
|
|
| MD5 |
09e5e74011f608d9f77ef8f22de806d3
|
|
| BLAKE2b-256 |
470d101fb476a4ab85cafc87858f21b4083177e907d60ff00d1fe6f2919e5d3a
|
Provenance
The following attestation bundles were made for dj_typed_settings-0.2.0.tar.gz:
Publisher:
publish.yml on adamghill/dj-typed-settings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_typed_settings-0.2.0.tar.gz -
Subject digest:
ec380de903cf29bf48e917335dc259a41d6f49c72fe6994333efc622c590200f - Sigstore transparency entry: 953291437
- Sigstore integration time:
-
Permalink:
adamghill/dj-typed-settings@d0cc43bcc98d1e6944f08be805ad671cef8f939a -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/adamghill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0cc43bcc98d1e6944f08be805ad671cef8f939a -
Trigger Event:
release
-
Statement type:
File details
Details for the file dj_typed_settings-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dj_typed_settings-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbe71654a614c8d3bde4839067c016b71ea3d4b1ed7fcc21b8673d39036f3179
|
|
| MD5 |
ec53b78c0d6982523159ce39d3eefc2e
|
|
| BLAKE2b-256 |
fbd784758b65621d1f92278587a6e1cfe675e9dc0d72607faa41578814fee405
|
Provenance
The following attestation bundles were made for dj_typed_settings-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on adamghill/dj-typed-settings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_typed_settings-0.2.0-py3-none-any.whl -
Subject digest:
cbe71654a614c8d3bde4839067c016b71ea3d4b1ed7fcc21b8673d39036f3179 - Sigstore transparency entry: 953291438
- Sigstore integration time:
-
Permalink:
adamghill/dj-typed-settings@d0cc43bcc98d1e6944f08be805ad671cef8f939a -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/adamghill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0cc43bcc98d1e6944f08be805ad671cef8f939a -
Trigger Event:
release
-
Statement type: