{"id":23500,"library":"dargs","title":"dargs","description":"Process arguments for the deep modeling project. Current version: 0.5.0.post0. Release cadence: irregular, with recent releases every few months. Supports Python >=3.7.","status":"active","version":"0.5.0.post0","language":"python","source_language":"en","source_url":"https://github.com/deepmodeling/dargs","tags":["argument-parsing","configuration","deep-learning","deepmodeling"],"install":[{"cmd":"pip install dargs","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"The main class for defining arguments.","wrong":"","symbol":"Argument","correct":"from dargs import Argument"},{"note":"Normalize input dictionary against argument definitions.","wrong":"","symbol":"normalize","correct":"from dargs import normalize"},{"note":"Remove leading whitespace from multi-line argument documentation.","wrong":"","symbol":"dedent","correct":"from dargs import dedent"},{"note":"Define variant arguments (e.g., different model types).","wrong":"","symbol":"Variant","correct":"from dargs import Variant"}],"quickstart":{"code":"from dargs import Argument, Variant, normalize\n\n# Define arguments\narg1 = Argument(\"learning_rate\", float, default=0.001)\narg2 = Argument(\"layers\", list, default=[128, 64])\n\n# Define a variant\nvariant = Variant(\"backend\", [\n    Argument(\"tensorflow\", dict, [\n        Argument(\"device\", str, default=\"GPU\")\n    ]),\n    Argument(\"pytorch\", dict, [\n        Argument(\"device\", str, default=\"CPU\")\n    ])\n])\n\n# Compile arguments\nargs = [arg1, arg2, variant]\n\n# Example user input\nuser_input = {\n    \"learning_rate\": 0.01,\n    \"layers\": [256, 128],\n    \"backend\": {\n        \"tensorflow\": {\"device\": \"TPU\"}\n    }\n}\n\n# Normalize (validate and apply defaults)\ntry:\n    normalized = normalize(args, user_input)\n    print(\"Normalized config:\", normalized)\nexcept Exception as e:\n    print(\"Error:\", e)","lang":"python","description":"Basic usage of dargs: define arguments with variants, then normalize user input."},"warnings":[{"fix":"Review usage of mutable defaults; consider using factory functions if sharing is needed.","message":"In v0.5.0, the `default` parameter may behave differently for mutable types (e.g., list, dict). Now defaults are deep-copied to avoid mutation sharing. If you rely on defaults being shared across calls, you must update your code to explicitly handle that.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Ensure user input structure matches the variant hierarchy exactly.","message":"When using Variant, the variant key (e.g., 'backend') must be a string, and the choice key must be exactly one of the defined variant names. Common mistake: nesting variant inside another variant incorrectly.","severity":"gotcha","affected_versions":"all"},{"fix":"Stop importing from dargs.cli; use Argument definitions and argparse for CLI.","message":"The `dargs.cli` module (exposed in v0.4.8) is deprecated in favor of using `Argument` directly with command-line parsing via `argparse`. The `dargs` CLI may be removed in future versions.","severity":"deprecated","affected_versions":">=0.4.8, <0.6.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Remove the extra key or add it to the argument list using Argument(...).","cause":"User input contains a key not defined in the argument specification.","error":"dargs.exceptions.DargsError: The argument 'X' is not defined."},{"fix":"Check the variant choices and provide a valid one; e.g., for backend, use 'tensorflow' or 'pytorch'.","cause":"The value for a variant field does not match any of the defined variant choices.","error":"dargs.exceptions.DargsError: The variant choice 'Y' is invalid."},{"fix":"Ensure the user input conforms to the expected types, or use a custom dtype validator.","cause":"A field value has a mismatched type compared to the Argument's dtype.","error":"dargs.exceptions.DargsError: Expected type 'int' but got 'str'."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}