disdantic.settings¶
Configuration settings orchestration for disdantic polymorphism.
This module provides the central settings schema utilizing Pydantic Settings to manage, validate, and load configuration parameters. It aggregates settings from multiple sources, including constructor arguments, environment variables, dotenv files, CLI inputs, and pyproject.toml configurations.
The primary interface is the Settings class, which defines validation schemas for paths, environment states, registry discriminator configurations, dynamic auto-discovery parameters, and validation compilation behaviors.
Settings
¶
Bases: BaseSettings
Central configuration store and validation schema for the disdantic package.
This class serves as the single source of truth for runtime configurations, defining default options and loading overrides dynamically across modules. It integrates with Pydantic's BaseSettings to enforce type validation, coercion, and environment prefixing.
Example
.. code-block:: python
from disdantic.settings import Settings, get_settings
# Initialize a localized settings instance
settings = Settings(default_schema_discriminator="custom_type")
assert settings.default_schema_discriminator == "custom_type"
# Retrieve the global settings singleton instance
global_settings = get_settings()
print(global_settings.project_root)
Source code in src/disdantic/settings.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
model_config = SettingsConfigDict(arbitrary_types_allowed=True, extra='ignore', populate_by_name=True, validate_assignment=True, env_prefix='DISDANTIC__', cli_prefix='disdantic_', cli_parse_args=True, pyproject_toml_table_header=('tool', 'disdantic'))
class-attribute
¶
Configuration dictionary defining Pydantic Settings behavior options.
Controls environment variables parsing prefix, CLI integration arguments, pyproject.toml headers, and assignment validation rules.
__repr__()
¶
Generate a detailed string representation of the settings.
:returns: A detailed debug string representation of the settings.
__str__()
¶
Generate a concise string representation of the settings.
:returns: A human-readable string summary of the configuration state.
settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)
classmethod
¶
Customize configuration loaders and define prioritize hierarchy.
This method overrides the default Pydantic source loading priorities to determine the resolving order of configuration options.
:param settings_cls: The settings class being constructed. :param init_settings: Settings passed directly to the class constructor. :param env_settings: Settings loaded from system environment variables. :param dotenv_settings: Settings loaded from active .env file streams. :param file_secret_settings: Settings loaded from secrets files paths. :returns: A tuple of settings sources ordered by loading priority.
Source code in src/disdantic/settings.py
get_settings()
¶
Retrieve the global Settings singleton instance.
Uses double-checked locking to resolve initialization race conditions in multi-threaded applications.
Example
.. code-block:: python
from disdantic.settings import get_settings
settings = get_settings()
print(settings.project_root)
:returns: The global Settings singleton instance.
Source code in src/disdantic/settings.py
reset_settings()
¶
Reset the global Settings singleton instance to None.
Forces a complete reload and re-validation of settings on the next invocation of get_settings().
Example
.. code-block:: python
from disdantic.settings import reset_settings
# Evicts active settings from memory
reset_settings()
:returns: None