Skip to main content

Pydantic-ish YAML configuration management.

Project description

DriConfig

driconfig

A Pydantic-ish way to manage your project's YAML configurations.

CI/CD Tests Coverage Status Tests types - Mypy Ruff
Package PyPI PyPI - Downloads PyPI - Python Version GitHub

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

driconfig-1.0.4.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

driconfig-1.0.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for driconfig-1.0.4.tar.gz
Algorithm Hash digest
SHA256 640394eadba0aa41723b50ea282698071e8f3381e8db16ec90a6ae6befdd3b82
MD5 187f38bba20880ef1ff5bbf9adf786b5
BLAKE2b-256 7c5255bdbff2cd24620b696b120cf67030e1ac61ba10b60def4460824f459416

See more details on using hashes here.

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

Hashes for driconfig-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1599e37d176b41248e0c31b9d142cebe3ba585631f71fa4cd34e9a7ed75ea5aa
MD5 5ac99b05e9a927b83a30a3887c2ae655
BLAKE2b-256 2d4fc13e89b305f1c716f04736a2ba3536041999a21e6db07e72f12e378c3d7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page