Skip to main content

Dataclass-driven configuration helpers with metadata, validation, path access, argparse integration, and documentation generation.

Project description

dc_options

Dataclass-first configuration helpers with validation, metadata, argparse wiring, and documentation export. dc_options lets you describe nested option trees using familiar dataclasses while automatically generating CLIs, enforcing constraints, and producing Markdown/reference docs.

Features

  • Declarative configuration via dataclasses and an option() helper carrying labels, ranges, choices, and UI hints.
  • Strict loading/saving from JSON using dacite with metadata validation baked in.
  • Path-based getters/setters (cfg.get("training.lr")) for ergonomic CLI or scripting overrides.
  • Argparse integration that maps metadata to command-line flags.
  • Documentation export using Jinja2 templates so UI teams and docs stay synced with code.

Project Layout

dc_options/         Core package (Options base class, metadata helper, docs template)
examples/           Minimal usage sample for experimentation
tests/              Pytest suites covering dump, path helpers, validation, etc.
pyproject.toml      uv/PEP 621 project definition
AGENTS.md           Contributor guide and workflow expectations

Getting Started

uv sync                             # install deps in .venv
uv run python examples/minimal.py   # inspect nested configs & path helpers
uv run python examples/argparse_example.py --serve.port 9090 --workers 4
uv run pytest tests -q              # run the test suite

To pull configuration from JSON or args:

from dc_options import Options, option

@dataclass
class Train(Options):
    epochs: int = option(default=10, min=1, label="Epochs")

cfg = Train.load("train.json")
cfg.validate()
parser = Train.build_argparser()
cfg.apply_cli_overrides(parser.parse_args())

Examples

  • examples/minimal.py shows nested option classes, validation, and get/set helpers that operate on dot paths.
  • examples/argparse_example.py demonstrates combining JSON loading with CLI overrides using build_argparser.

Documentation

  • Update option metadata before exporting docs; the default template lives in dc_options/docs_template.md.j2.
  • Generate fresh docs with uv run python - <<'PY' ... Options.export_docs(...).
  • Preview site content through MkDocs (mkdocs serve) if documentation is published.

Metadata Reference

  • label / description – available for every field; provide human-readable names and context.
  • editable – all field types; mark values that should be read-only in generated UIs.
  • min, max, step – numeric fields (int/float); used for validation and slider widgets.
  • choices, labels – enumerations (str, int, etc.); specify allowed values and friendly labels.
  • default, default_factory – all fields; stored in metadata for resets or documentation.

Contributing

Follow AGENTS.md for project structure tips, coding style, testing expectations, and git hygiene. Every feature or fix should ship with regression tests and refreshed docs whenever CLI behavior or configuration metadata changes.

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

dc_options-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

dc_options-0.2.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file dc_options-0.2.0.tar.gz.

File metadata

  • Download URL: dc_options-0.2.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dc_options-0.2.0.tar.gz
Algorithm Hash digest
SHA256 86403a4eb0020e4d29386ad2ebd23f6b7ead932475b95232edb840a6cb8a9d4d
MD5 a543df3fccb646a76e77001a4b06c810
BLAKE2b-256 337d6f5f07987713bb56b942a36c483783186f53e455d21c3a003c7f03434751

See more details on using hashes here.

File details

Details for the file dc_options-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dc_options-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dc_options-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82fe8fbaa3864377157ca626fc14382adaeff81daef932571b04a9a6b8d617f1
MD5 1e1ebd7e6f9d511e492c03413d389f1a
BLAKE2b-256 77d22a656514a63ed594617566a3152798f6dd1766e21d61f61332be5ace66b2

See more details on using hashes here.

Supported by

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