Skip to main content

Pydantic-ish YAML configuration management.

Project description

DriConfig

driconfig

Test Lint Publish Docs Coverage PyPI version PyPI downloads

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 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"
    }
}
"""

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.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

driconfig-1.0.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: driconfig-1.0.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.5.0-1021-azure

File hashes

Hashes for driconfig-1.0.3.tar.gz
Algorithm Hash digest
SHA256 48dff5a68da8c9434e8223b7a80c916ebe97d4364b8298c7b1aefdc34f9ad0e9
MD5 cfc1ad67fb7b0a366c363f985f4465ea
BLAKE2b-256 322085f6fdfc8d4ca69214b82c3cf2c1e21f219df930c71ea6b95ea71aa5ffa3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: driconfig-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.5.0-1021-azure

File hashes

Hashes for driconfig-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78c95c29ae88fe2af2a48f084f7819c4d1960f5ea66550fbde1713f8bc5dbd5c
MD5 840f0cc4da196d365a6a48bb4cde89cc
BLAKE2b-256 1c0df0df9d5937fdbbc6d3639d61350ed926aed06db5364b223278315d13f03f

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