Registry / web-framework / django-split-settings

django-split-settings

JSON →
library1.3.2pypypi✓ verified 86d ago

django-split-settings helps organize Django settings into multiple files and directories, allowing for easier overriding and modification. It supports wildcards, optional settings files, and includes/merges settings from various sources. The current version is 1.3.2, with a release cadence that addresses bugfixes and adds support for newer Python and Django versions.

pip install django-split-settings
INSTALL
IMPORT
SIG · DJANGO-SPLIT-SETTI
D
django-split-settings
web-frameworkpythonv1.3.2
Install
1.5s avg
Import
12ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.013s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.012s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

include
from split_settings.tools import include
from split_settings.tools import include, optional, apply_modifiers
While 'optional' and 'apply_modifiers' are also from 'split_settings.tools', 'include' is the primary function for splitting settings. Importing all three in a single statement is not wrong, but 'include' is the most essential and frequently used.
optional
from split_settings.tools import optional

This quickstart demonstrates a typical setup for django-split-settings. In your `settings/__init__.py` file (or directly in your main `settings.py`), you import `include` and `optional`. You then use `include` to pull in other settings files, often starting with a `base.py` for common configurations, followed by environment-specific or local override files. The `optional()` wrapper ensures that your application doesn't crash if an included file (e.g., a developer's `local.py`) doesn't exist.

import os from split_settings.tools import include, optional BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Include settings from base.py include(optional('base.py')) # Include environment-specific settings (e.g., local.py, production.py) # The '*' wildcard includes all matching files. # Using 'optional' prevents errors if a file doesn't exist. # 'settings/*' would include files in a 'settings' subdirectory. include( optional('environment/*.py'), optional('local.py') ) # Example of a setting, potentially overridden by included files DEBUG = True ALLOWED_HOSTS = ['*'] # Example of how you might structure settings files: # # settings/ # ├── __init__.py (This file) # ├── base.py (Common settings) # ├── environment/ # │ ├── dev.py (Development environment settings) # │ └── prod.py (Production environment settings) # └── local.py (Local overrides, usually excluded from VCS)
Debug
Known issues
breakingThe `include()` function signature changed in version 1.3.0. Keyword arguments like `globals` or `locals` are no longer supported. Instead, use the `scope` keyword argument for explicit scope passing.
fix
Replace `include('file.py', globals=globals())` with `include('file.py', scope=globals())`. If you were passing other unsupported keyword arguments, remove them as they were not functional prior to 1.3.0 anyway.
affects: >=1.3.0
breakingPython 3.8 support was dropped in version 1.3.0. Users on Python 3.8 will need to upgrade their Python version to 3.9 or newer to use django-split-settings >= 1.3.0.
fix
Upgrade your Python environment to 3.9, 3.10, 3.11, or 3.12.
affects: >=1.3.0
gotchaAttempting to include a non-existent file without wrapping it in `optional()` will raise a `FileNotFoundError`. This is common for local development override files (e.g., `local.py`) that are not committed to version control.
fix
Always wrap paths to potentially missing settings files with `optional()`, for example: `include(optional('local.py'))`.
affects: all
breakingPython 2 and Django 2.0 support was dropped in version 1.0.0. Projects using these older versions must remain on django-split-settings < 1.0.0.
fix
Upgrade your Django and Python versions to modern supported releases, or pin `django-split-settings<1.0.0`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: include() got an unexpected keyword argument 'globals'
Using `globals=globals()` or similar keyword arguments with `include()` in versions 1.3.0 or newer.
fix
The `include` signature changed. Replace `globals=globals()` with `scope=globals()`. For example, `include('file.py', scope=globals())`.
ModuleNotFoundError: No module named 'split_settings.tools'
The `django-split-settings` package is not installed in the current Python environment or you are trying to import from an incorrect path.
fix
Install the package using `pip install django-split-settings`. Ensure your virtual environment is activated if applicable.
FileNotFoundError: [Errno 2] No such file or directory: 'settings/local.py'
You are attempting to `include()` a settings file that does not exist, and you have not wrapped the path with `optional()`.
fix
Wrap the path of the potentially missing file with `optional()`: `include(optional('settings/local.py'))`.
Upgrade
Version history
1.3.2latest on PyPI · released Jul 5, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
2
Resources
django-split-settings — pip install django-split-settings · libregistry