Registry / serialization / draccus

draccus

JSON →
library0.11.5pypypi✓ verified 33d ago

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.

serializationweb-framework
Install & Compatibility
Where this runs
tested against v0.11.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.112s · 21.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.0s · import 0.101s · 23MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from draccus import wrap
from draccus import field
from draccus import ConfigType

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()
Debug
Known footguns
gotchaDraccus is a fork of Pyrallis. While it maintains much of Pyrallis's API, it introduces unique features like subtyping and nested config file inclusion. Code expecting direct Pyrallis behavior for these advanced scenarios might need adaptation.
gotchaWhen using the `@draccus.wrap()` decorator, the decorated function's parameters are automatically populated by the parsed configuration. Avoid manually calling `draccus.parse()` within a function already wrapped by `@draccus.wrap()` unless a separate parsing context is explicitly intended.
deprecatedEarlier versions might have used `draccus.parse()` as the primary entry point. While still available, `@draccus.wrap()` is generally recommended for top-level application configuration due to its seamless integration.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
58 hits · last 30 days
chatgpt-user
8
googlebot
5
gptbot
4
ahrefsbot
4
oai-searchbot
4
bytedance
3
script
1
Resources