Pydantic-ish YAML configuration management.
Project description
DriConfig
A Pydantic-ish way to manage your project's YAML configurations.
CI/CD | |
Package |
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.
Installation
This project resides in the Python Package Index (PyPI), so it can easily be installed with pip
:
pip install driconfig
Usage
You can import the DriConfig
class from the driconfig
package and create your own configuration classes.
from driconfig import DriConfig
Examples
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 configparse with driconfig
as follows:
from datetime import date
from typing import Dict
from driconfig import DriConfig, DriConfigConfigDict
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."""
"""Configure the YAML file location."""
model_config = DriConfigConfigDict(
config_folder=".",
config_file_name="config.yaml",
)
model_parameters: Dict[str, float]
date_interval: DateInterval
config = AppConfig()
print(config.model_dump_json(indent=4))
"""
{
"model_parameters": {
"eta": 0.2,
"gamma": 2.0,
"lambda": 1.0
},
"date_interval": {
"start": "2021-01-01",
"end": "2021-12-31"
}
}
"""
Contributing
Poetry is the best way to interact with this project. To install it, follow the official Poetry installation guide.
With poetry
installed, one can install the project dependencies with:
poetry install
Then, to run the project unit tests:
make test
To run the linters (ruff
and mypy
):
make lint
License
driconfig
is distributed under the terms of the
MIT license.
Check the LICENSE file for further details.
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-1.0.4.tar.gz
.
File metadata
- Download URL: driconfig-1.0.4.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.0 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 640394eadba0aa41723b50ea282698071e8f3381e8db16ec90a6ae6befdd3b82 |
|
MD5 | 187f38bba20880ef1ff5bbf9adf786b5 |
|
BLAKE2b-256 | 7c5255bdbff2cd24620b696b120cf67030e1ac61ba10b60def4460824f459416 |
File details
Details for the file driconfig-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: driconfig-1.0.4-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.0 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1599e37d176b41248e0c31b9d142cebe3ba585631f71fa4cd34e9a7ed75ea5aa |
|
MD5 | 5ac99b05e9a927b83a30a3887c2ae655 |
|
BLAKE2b-256 | 2d4fc13e89b305f1c716f04736a2ba3536041999a21e6db07e72f12e378c3d7c |