draccus

0.11.5 · active · verified Tue Apr 14

Draccus is a Python library that provides a slightly opinionated framework for simple dataclass-based configurations, built as a fork of Pyrallis. It extends Pyrallis with advanced features such as support for subtyping configurations, the ability to include config files within other config files, and enhanced handling for containers of configurations. The current version is 0.11.5.

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a simple dataclass for configuration and use the `@draccus.wrap()` decorator to parse command-line arguments or YAML files into an instance of that dataclass. Run it from the command line, for example: `python your_script.py --exp_name=my_first_exp --workers=4`.

from dataclasses import dataclass
import draccus

@dataclass
class TrainConfig:
    """Training Config for Machine Learning"""
    workers: int = 8  # The number of workers for training
    exp_name: str = 'default_exp' # The experiment name

@draccus.wrap()
def main(cfg: TrainConfig):
    print(f"Training {cfg.exp_name} with {cfg.workers} workers...")

if __name__ == "__main__":
    main()

view raw JSON →