API

Organize Django settings into multiple files and directories.

Easily override and modify settings. Use wildcards and optional settings files.

class _Optional[source]

Bases: str

Wrap a file path with this class to mark it as optional.

Optional paths don’t raise an OSError if file is not found.

optional(filename)[source]

This function is used for compatibility reasons.

It masks the old optional class with the name error. Now invalid-name is removed from pylint.

Parameters:

filename (Optional[str, None]) – the filename to be optional.

Return type:

str

Returns:

New instance of _Optional.

include(*args, scope=None)[source]

Used for including Django project settings from multiple files.

Parameters:
  • *args – File paths (glob - compatible wildcards can be used).

  • scope (UnionType[dict[str, Any], None]) – Settings context (globals() or None).

Raises:

OSError – if a required settings file is not found.

Usage example:

from split_settings.tools import optional, include

include(
    'components/base.py',
    'components/database.py',
    optional('local_settings.py'),

    scope=globals(),  # optional scope
)
Return type:

None