{"id":3401,"library":"argparse-addons","title":"argparse-addons","description":"argparse-addons is a Python library that provides additional types and actions for the standard library's `argparse` module, enhancing command-line interface creation. The current version is 0.12.0. The project maintains a somewhat active release cadence, with the last update in January 2023.","status":"active","version":"0.12.0","language":"en","source_language":"en","source_url":"https://github.com/eerimoq/argparse_addons","tags":["argparse","cli","command-line","utilities","types"],"install":[{"cmd":"pip install argparse-addons","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"Integer","correct":"from argparse_addons import Integer"}],"quickstart":{"code":"import argparse\nfrom argparse_addons import Integer\n\nparser = argparse.ArgumentParser(description='Process some integers.')\nparser.add_argument(\n    '--value', \n    type=Integer(0, 255), \n    help='An integer value between 0 and 255.'\n)\n\nargs = parser.parse_args(['--value', '128'])\nprint(f'Parsed value: {args.value}')\n\n# Example of invalid input (will raise an error during parse_args)\n# try:\n#     parser.parse_args(['--value', '-1'])\n# except SystemExit as e:\n#     print(f'Error: {e}')","lang":"python","description":"This quickstart demonstrates how to define an argument using the `Integer` type from `argparse-addons`, enforcing a value within a specified range. It uses a standard `argparse.ArgumentParser` instance."},"warnings":[{"fix":"Wrap `ArgumentParser` creation and `parse_args()` calls in `if __name__ == \"__main__\":`.","message":"Calling `parser.parse_args()` at the top level of an imported module can lead to unexpected argument parsing behavior or errors in the main script. Always guard `ArgumentParser` instantiation and `parse_args()` calls within an `if __name__ == \"__main__\":` block if the module is intended to be imported.","severity":"gotcha","affected_versions":"All versions of argparse-addons (inherent argparse behavior)"},{"fix":"Consider if `nargs='*'` is truly appropriate with `choices` for positional arguments, or explicitly add `[]` to your `choices` (though this might clutter help output). Alternatively, ensure a default is set that is within `choices`.","message":"When a positional argument is defined with `nargs='*'` (zero or more arguments) and also `choices`, providing no values for that argument can result in an 'invalid choice: []' error, because `argparse` attempts to validate an empty list against the defined choices.","severity":"gotcha","affected_versions":"All versions of argparse-addons (inherent argparse behavior)"},{"fix":"Avoid using `default` directly with `action='append'` or `action='extend'` if the intention is for the user's input to completely replace the default. Instead, handle default list population manually after `parse_args()`.","message":"The interaction between `default` values and actions like `action='append'` or `action='extend'` can be non-intuitive. Default values might be prepended to user-provided input, making it difficult to completely override the default without custom logic.","severity":"gotcha","affected_versions":"All versions of argparse-addons (inherent argparse behavior)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}