Skip to main content

Pydantic-ish YAML configuration management.

Project description

driconfig

Test Publish Coverage Package version

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

driconfig-0.2.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

driconfig-0.2.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file driconfig-0.2.1.tar.gz.

File metadata

  • Download URL: driconfig-0.2.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.8.16 Linux/5.15.0-1034-azure

File hashes

Hashes for driconfig-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f0d3f17e16ea12ec3d1a163136f470d4989f26df2263874e9264ec6170f1afed
MD5 1ad3ab4932073c819ba326760ed05841
BLAKE2b-256 a816fc3aaf0ec530d69cf3d8309faeea78ee054d16cb1db434fcd9d53c828c7e

See more details on using hashes here.

File details

Details for the file driconfig-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: driconfig-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.8.16 Linux/5.15.0-1034-azure

File hashes

Hashes for driconfig-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c4fd8fe4b270bd11d6d2c869fb0aaf01de6bd0986f2b1c6a5c69698622f8680
MD5 f49e85953e1133484ad6c6b7944883c3
BLAKE2b-256 03a87c421c5272ebaa405491b092e31375d1677c1a15d6faba98bd2a1532ffb1

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