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
Release history Release notifications | RSS feed
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
File details
Details for the file driconfig-0.2.0.tar.gz
.
File metadata
- Download URL: driconfig-0.2.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.7.12 Linux/5.11.0-1028-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32c6a9e2714874d1b17ab6cf63d2427fb46e798f53505b373993117b24ef9e71 |
|
MD5 | 063076fe7b1cda9f9289877126dfcb52 |
|
BLAKE2b-256 | 3d33ff2ba49d6053a97702042f2bd7c5fda45cbe8e09a785f38e5281a3d35b8b |
File details
Details for the file driconfig-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: driconfig-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.7.12 Linux/5.11.0-1028-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57283cc63819b705c939a0b8009fef03a65668a27c1dc3f217deaf44bacaefc4 |
|
MD5 | 8836c8e71c9a76c88f5d8d9e92c7441e |
|
BLAKE2b-256 | 5323141ce537f6b883059b4b864b9572f197735f3ae56a4be0d64dd040b363d8 |