Config¶
churn_prediction.config.settings
¶
Application Settings and Configuration Management.
This module defines the type-safe application configuration schema using
Pydantic Settings and Pydantic v2. It manages environment variables, .env file
overrides, runtime directories, and hyperparameter configuration (params.yaml).
Environment
¶
Bases: StrEnum
Enumeration of supported application logging levels.
EvaluateParams
¶
Bases: ImmutableBaseModel
Define model evaluation and classification configuration.
Contains the decision threshold and other settings used to evaluate model performance on the validation dataset.
ImmutableBaseModel
¶
Bases: BaseModel
Base Pydantic model enforcing immutable and strict configuration.
Subclasses inherit validation behavior intended to prevent accidental mutation of application configuration after initialization.
LogLevel
¶
Bases: StrEnum
Enumeration of logging levels.
MetadataParams
¶
PipelineParams
¶
Bases: ImmutableBaseModel
Define the complete validated pipeline configuration.
Aggregates dataset schema, preprocessing, training, evaluation, and metadata configuration into a single type-safe parameter object.
load_from_yaml(path=DEFAULT_PARAMS_FILE)
classmethod
¶
Load and validate pipeline parameters from a YAML configuration file.
The YAML contents are parsed into the validated parameter model. If the configuration file does not exist, the model's default configuration is returned instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the YAML parameter configuration file. |
DEFAULT_PARAMS_FILE
|
Returns:
| Type | Description |
|---|---|
PipelineParams
|
Validated pipeline parameter configuration. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the YAML file exists but contains invalid parameter values or cannot be parsed into the expected configuration schema. |
Source code in src/churn_prediction/config/settings.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
PreprocessingParams
¶
Bases: ImmutableBaseModel
Define preprocessing configuration for model-ready datasets.
Contains the feature transformation settings used consistently during training and inference.
SchemaParams
¶
Bases: ImmutableBaseModel
Define dataset schema and feature configuration.
Stores the column definitions and feature groups used to validate, preprocess, and model the churn prediction datasets.
Settings
¶
Bases: BaseSettings
Define validated application-wide runtime configuration.
Configuration values are loaded from environment variables and the
project-level .env file, with environment variables taking
precedence.
The settings object contains runtime paths, logging configuration, external service credentials, API configuration, model settings, and computed artifact locations.
Notes
Unknown configuration values are ignored, and environment variable names are matched case-insensitively.
PARAMS
property
¶
Return the lazily loaded pipeline configuration.
Loads and validates params.yaml on first access and caches the
resulting configuration for subsequent accesses.
Returns:
| Type | Description |
|---|---|
PipelineParams
|
Validated pipeline hyperparameters and processing configuration. |
assemble_api_urls()
¶
Construct API endpoint URLs from the configured host and port.
Derives the URLs used by the prediction, download, explainability, and health-check clients from the application's API host and port settings.
Source code in src/churn_prediction/config/settings.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
ensure_directories()
¶
Create required application workspace directories.
Ensures that directories required for data ingestion, preprocessing, models, reports, predictions, logs, and other runtime artifacts exist. Existing directories are left unchanged.
Source code in src/churn_prediction/config/settings.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
TrainParams
¶
Bases: ImmutableBaseModel
Define model training configuration.
Stores XGBoost parameters and training controls such as boosting rounds, early stopping, and evaluation verbosity.
XGBoostParams
¶
get_settings()
cached
¶
Return the cached application settings.
Local development may use a project-level environment file, while deployment environments such as Render provide configuration directly through environment variables.
Source code in src/churn_prediction/config/settings.py
395 396 397 398 399 400 401 402 403 404 405 406 | |
churn_prediction.config.logger
¶
Structured Application Logging Module.
Implements a centralized logging system that provides formatted console output and rotating file logs. It is designed to be thread-safe and prevents duplicate handler initialization in concurrent environments.
LoggingLifecycle
¶
Track the process-local state of logging configuration.
This internal helper provides thread-safe state management for the application logging lifecycle. It prevents multiple concurrent callers from configuring the logging system more than once.
Attributes:
| Name | Type | Description |
|---|---|---|
_lock |
Lock
|
Lock protecting logging initialization from concurrent access. |
_is_configured |
bool
|
Whether application-wide logging has been successfully configured. |
is_configured()
classmethod
¶
Return whether application logging has been configured.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/churn_prediction/config/logger.py
41 42 43 44 45 46 47 48 49 50 51 | |
mark_configured()
classmethod
¶
Mark application logging as successfully configured.
Source code in src/churn_prediction/config/logger.py
53 54 55 56 | |
configure_logging(*, force=False)
¶
Configure application-wide structured logging.
Initializes Structlog, console output, rotating file logging, third-party logger handling, standard warning capture, and optional Sentry error monitoring.
Configuration is idempotent by default. If logging has already been
configured, subsequent calls have no effect unless force=True is
specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
Whether to rebuild the logging configuration when logging has already
been initialized. When |
False
|
Source code in src/churn_prediction/config/logger.py
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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
get_logger(name=None)
¶
Return a configured application logger.
Logging configuration is initialized lazily if it has not already been configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str or None
|
Logger name to bind to the returned logger. If |
None
|
Returns:
| Type | Description |
|---|---|
BoundLogger
|
Configured Structlog logger suitable for structured application logging. |
Source code in src/churn_prediction/config/logger.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |