Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Placeholder for future updates and new features.
## [1.4.0] - 2026-05-04

### Changed
- Replaced `PyYAML` with `omegaconf~=2.3.0` for the `yaml` config option (closes #98). OmegaConf is a superset of PyYAML that adds variable interpolation (`${key}`), config merging, and optional runtime type safety via Structured Configs. The `load_config()` function now returns `DictConfig` instead of `Dict`, which supports both dict-style (`config['key']`) and dot-notation (`config.key`) access.

## [1.3.0] - 2026-01-27

Expand Down
29 changes: 28 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "at-python-template"
version = "1.3.0"
version = "1.4.0"
description = "This is the official Python Project Template of Alexander Thamm GmbH (AT)"
authors = [
"Christian Baur <christian.baur@alexanderthamm.com>",
Expand All @@ -21,6 +21,7 @@ pre-commit = "^4.5.1"
pytest-mock = "^3.15.1"
pyhocon = "^0.3.61"
pyyaml = "^6.0.3"
omegaconf = "^2.3.0"
typer = "^0.21.1"
setuptools = "^80.10.2"
requests = ">=2.32.5"
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ channels:
dependencies:
- python>=3.10{% if cookiecutter.config_file == 'hocon' %}
- pyhocon>=0.3.61{% elif cookiecutter.config_file == 'yaml' %}
- PyYAML>=6.0.3{% endif %}
- omegaconf>=2.3.0{% endif %}
- pip {% if cookiecutter.create_cli == 'yes' %}
- pip:
- typer==0.21.1{% endif %}
4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python = "^3.10"
{%- if cookiecutter.config_file == 'hocon' %}
pyhocon = "^0.3.61"
{%- elif cookiecutter.config_file == 'yaml' %}
PyYAML = "^6.0.3"
omegaconf = "^2.3.0"
{%- endif %}
{%- if cookiecutter.create_cli == 'yes' %}
typer = "^0.21.1"
Expand Down Expand Up @@ -74,7 +74,7 @@ dependencies = [
{%- if cookiecutter.config_file == 'hocon' %}
"pyhocon>=0.3.59",
{%- elif cookiecutter.config_file == 'yaml' %}
"PyYAML>=6.0",
"omegaconf>=2.3.0",
{%- endif %}
{%- if cookiecutter.create_cli == 'yes' %}
"typer>=0.16.1",
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# HOCON configuration parser
pyhocon~=0.3.61
{% elif cookiecutter.config_file == 'yaml' %}
# YAML configuration parser
PyYAML~=6.0.2
# YAML configuration parser (with interpolation and merging support)
omegaconf~=2.3.0
{% endif %}

# Dependency for Command-Line Interface (CLI) if enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from pathlib import Path
from typing import Any, Dict, Union
from typing import Union

import importlib.resources as resources
import yaml
from omegaconf import DictConfig, OmegaConf

logger = logging.getLogger('{{ cookiecutter.module_name }}')

Expand All @@ -23,27 +23,29 @@ def get_resource_string(path: str, decode=True) -> Union[str, bytes]:
return s.decode(errors='ignore') if decode else s


def load_config(config_file: Union[str, Path]) -> Dict[str, Any]:
def load_config(config_file: Union[str, Path]) -> DictConfig:
"""
Load the config from the specified yaml file
Load the config from the specified YAML file.

Uses OmegaConf, which supports variable interpolation (${key}) and config
merging on top of standard YAML. See https://omegaconf.readthedocs.io/

:param config_file: path of the config file to load
:return: the parsed config as dictionary
:return: the parsed config as a DictConfig (supports both dict and dot-notation access)
"""
with open(config_file) as fp:
return yaml.safe_load(fp)
return OmegaConf.load(config_file)


def logging_setup(config: Dict):
def logging_setup(config: DictConfig):
"""
setup logging based on the configuration
Setup logging based on the configuration.

:param config: the parsed config tree
"""
log_conf = config['logging']
fmt = log_conf['format']
if log_conf['enabled']:
level = logging._nameToLevel[log_conf['level'].upper()]
log_conf = config.logging
fmt = log_conf.format
if log_conf.enabled:
level = logging._nameToLevel[log_conf.level.upper()]
else:
level = logging.NOTSET
logging.basicConfig(format=fmt, level=logging.WARNING)
Expand Down