Configuration Settings¶
This document details sayer/conf/settings.py, which manages dynamic configuration for Sayer.
Overview¶
The Settings class provides a centralized configuration system, layered with environment variables and in-memory overrides.
Key Components¶
ENVIRONMENT_VARIABLE: Defines the environment variable (SAYER_SETTINGS_MODULE) that can point to a custom settings module.SettingsForward: A proxy descriptor that forwards attribute access to the actualSettingsinstance.settings: A globally available proxy instance ofSettings, used throughout Sayer.
Usage¶
from sayer.conf import settings
print(settings.debug)
settings.debug = True
print(settings.debug)
How It Works¶
- In-Memory Overrides: Attributes set on
settingsoverride environment variables. - Environment Variables:
settingschecks the environment if an attribute is not set in memory. - Fallback: If neither is set, defaults are used from
global_settings.
Best Practices¶
- ✅ Use
settingsfor accessing and modifying global configuration. - ✅ Define a custom settings module and set
SAYER_SETTINGS_MODULEfor environment-specific configs. - ❌ Avoid hardcoding settings; use
settingseverywhere.