{"id":9488,"library":"argparse-ext","title":"argparse-ext","description":"argparse-ext is a Python library that extends the standard `argparse` module, providing additional argument types and features for command-line interface parsing. It offers types like path, URL, JSON, email, and utilities for subcommands and config files. The current version is 1.4.2, and it maintains a steady, though not rapid, release cadence.","status":"active","version":"1.4.2","language":"en","source_language":"en","source_url":"https://github.com/cykerway/argparse-ext/","tags":["argparse","command-line","cli","parser","extension","pathlib","url"],"install":[{"cmd":"pip install argparse-ext","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"To use the extended features and types provided by argparse-ext, you must import its custom ArgumentParser class, not the standard one.","wrong":"from argparse import ArgumentParser","symbol":"ArgumentParser","correct":"from argparse_ext import ArgumentParser"}],"quickstart":{"code":"from argparse_ext import ArgumentParser\n\nparser = ArgumentParser(prog='my_cli_tool')\nparser.add_argument('--path', type='path', help='A path argument which becomes a pathlib.Path object')\nparser.add_argument('--url', type='url', help='A URL argument which becomes a urllib.parse.ParseResult object')\nparser.add_argument('--config', type='json', help='A JSON string which is parsed into a Python object')\n\nargs = parser.parse_args(['--path', '/tmp/foo.txt', '--url', 'http://example.com/foo', '--config', '{\"key\": \"value\"}']) # Simulate args for quickstart\n\nprint(f\"Path object type: {type(args.path)}, absolute: {args.path.absolute()}\")\nprint(f\"URL object type: {type(args.url)}, scheme: {args.url.scheme}\")\nprint(f\"Config object type: {type(args.config)}, value: {args.config['key']}\")\n","lang":"python","description":"This quickstart demonstrates how to import and use `argparse_ext.ArgumentParser` with some of its extended types like 'path', 'url', and 'json'. It also shows how to access the methods and attributes of the resulting parsed objects."},"warnings":[{"fix":"Replace `from argparse import ArgumentParser` with `from argparse_ext import ArgumentParser` at the top of your script.","message":"Ensure you use `argparse_ext.ArgumentParser` when utilizing extended argument types (e.g., `type='path'`, `type='url'`). Standard `argparse.ArgumentParser` does not recognize these custom types and will raise a `ValueError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the argparse-ext documentation for each extended type to understand its resolved object type and access its specific methods/attributes (e.g., `args.path.absolute()` or `args.url.scheme`).","message":"Extended types parse arguments into specific Python objects, not just strings. For example, `type='path'` becomes a `pathlib.Path` object, and `type='url'` becomes a `urllib.parse.ParseResult` object. Do not assume they remain simple strings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Choose distinct subcommand names. If issues arise, explicitly check `args.command_name` (or whatever destination you set) for the subcommand that was parsed.","message":"When using `add_subcommand`, ensure that the subcommand name does not conflict with any existing arguments or built-in methods of the `ArgumentParser`. While rare, such conflicts can lead to unexpected parsing behavior or errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"You must import and use `argparse_ext.ArgumentParser`. Change `from argparse import ArgumentParser` to `from argparse_ext import ArgumentParser`.","cause":"Attempting to use an `argparse-ext` custom type (like 'path', 'url', 'json') with the standard `argparse.ArgumentParser`.","error":"ValueError: invalid choice: 'path' (choose from 'str', 'int', 'float', ...)"},{"fix":"Verify that you are importing and using `argparse_ext.ArgumentParser`. The custom type conversion only occurs when using `argparse-ext`'s specialized parser.","cause":"The argument processed with `type='path'` (or similar extended type) was not correctly converted into its corresponding object (e.g., `pathlib.Path`). This usually happens because the standard `argparse.ArgumentParser` was used, returning a string.","error":"AttributeError: 'str' object has no attribute 'absolute'"}]}