Pydantic-ish YAML configuration management.
Project description
A Pydantic-ish way to manage your project's YAML configurations.
Documentation: https://dribia.github.io/driconfig
Source Code: https://github.com/dribia/driconfig
The usage of YAML files to store configurations and parameters is widely accepted in the Python community, especially in Data Science environments.
DriConfig provides a clean interface between your Python code and these YAML configuration files.
It is heavily based on Pydantic's Settings Management, preserving its core functionalities and advantages.
Key features
- Subclassing the
DriConfig
class we create an interface to any YAML configuration file. - Our project's configurations are then attributes of this class.
- They are automatically filled with the values in the YAML configuration file.
- We can define complex configuration structures using Pydantic models.
- We preserve Pydantic's type casting and validation!
Example
Let's say we have a YAML configuration file config.yaml
with the following data:
# config.yaml
model_parameters:
eta: 0.2
gamma: 2
lambda: 1
date_interval:
start: 2021-01-01
end: 2021-12-31
Then we can parse with driconfig
as follows:
from datetime import date
from typing import Dict
from driconfig import DriConfig
from pydantic import BaseModel
class DateInterval(BaseModel):
"""Model for the `date_interval` configuration."""
start: date
end: date
class AppConfig(DriConfig):
"""Interface for the config/config.yaml file."""
class Config:
"""Configure the YAML file location."""
config_folder = "."
config_file_name = "config.yaml"
model_parameters: Dict[str, float]
date_interval: DateInterval
config = AppConfig()
print(config.json(indent=4))
"""
{
"model_parameters": {
"eta": 0.2,
"gamma": 2.0,
"lambda": 1.0
},
"date_interval": {
"start": "2021-01-01",
"end": "2021-12-31"
}
}
"""
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for driconfig-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a01c965a61f1ffbcf4c335a53df6e14461b5af4d6f8718ad1e1f5ca3681e85c6 |
|
MD5 | 1e88e12620ec267b51cf5e2e0ca3dbc3 |
|
BLAKE2b-256 | 6eceb287ac9e40400bb0567119f6cc84a5c65adcaef37c9eb527ad32c7ce99fc |