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.

Using uv (recommended)

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.

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

driconfig-1.2.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: driconfig-1.2.2.tar.gz
  • Upload date:
  • Size: 128.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}

File hashes

Hashes for driconfig-1.2.2.tar.gz
Algorithm Hash digest
SHA256 511dd2309f8b431df34af85171fba13d4c168dcac083854fc35be8ba910a02a9
MD5 36e05e570234f7ecc9813829e583457e
BLAKE2b-256 325af9e8ae8ac6d713ad7e3409f21c5423361bec5a8140149dcf9ddb0f59b755

See more details on using hashes here.

File details

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

File metadata

  • Download URL: driconfig-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}

File hashes

Hashes for driconfig-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 125ccae13a404ab1040b774e2d4bfddecd5b0041603d74418ae6d416d8908c22
MD5 16c307d8502a0f2a443e45f3c1315d2c
BLAKE2b-256 9e26452642751371d8219d680ac1b37c0579034e89fd04bc4f201c36c6885ede

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 files

1.2.1

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page