Skip to main content

DriConfig

driconfig

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

CI/CD Lint Tests Coverage Status Ruff ty
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.

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!

Installation

This project resides in the Python Package Index (PyPI), so it can easily be installed with uv or pip.

uv is a fast Python package installer and resolver.

uv pip install driconfig

Or add it to your project:

uv add driconfig

Using 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

Check the CONTRIBUTING site for guidelines on how to contribute to this project.

License

DriConfig is distributed under the terms of the MIT license. Check the LICENSE file for further details.

Metadata

Release files for driconfig 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for driconfig 1.2.3
File Size Uploaded
driconfig-1.2.3.tar.gz 135.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for driconfig 1.2.3
File Interpreter ABI Platform
driconfig-1.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 142.4 kB

Release files / driconfig-1.2.3.tar.gz

Download URL driconfig-1.2.3.tar.gz
Size 135.6 kB
Tags Source
SHA-256 checksum
How to use checksums
20eb257116b537e1853fdfb9c304a89507ffd0f6970e18a2c05f975a2d613f59
BLAKE2b-256 checksum
How to use checksums
217a892192679b6805a7587d1f984c7b1d5b9f9a74f5c6405b3f91d912d7a675
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / driconfig-1.2.3-py3-none-any.whl

Download URL driconfig-1.2.3-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06204e12da3e6c511819b44578b5973c86aa774ec76e67f6a220d4f300ddc908
BLAKE2b-256 checksum
How to use checksums
71ff8c7bec7115bc39583b235246f996eda5245359eaf4dbb121a520921b4b81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page