Registry / http-networking / argparse-addons

argparse-addons

JSON →
library0.12.0pypypi✓ verified 23d ago

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.

pip install argparse-addons
INSTALL
IMPORT
SIG · ARGPARSE-ADDONS
A
argparse-addons
http-networkingpythonv0.12.0
Install
1.5s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.12.0 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.006s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.006s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

Integer
from argparse_addons import Integer

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.

import argparse from argparse_addons import Integer parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument( '--value', type=Integer(0, 255), help='An integer value between 0 and 255.' ) args = parser.parse_args(['--value', '128']) print(f'Parsed value: {args.value}') # Example of invalid input (will raise an error during parse_args) # try: # parser.parse_args(['--value', '-1']) # except SystemExit as e: # print(f'Error: {e}')
Debug
Known issues
gotchaCalling `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.
fix
Wrap `ArgumentParser` creation and `parse_args()` calls in `if __name__ == "__main__":`.
affects: All versions of argparse-addons (inherent argparse behavior)
gotchaWhen 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.
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`.
affects: All versions of argparse-addons (inherent argparse behavior)
gotchaThe 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.
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()`.
affects: All versions of argparse-addons (inherent argparse behavior)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'argparse_addons'
The 'argparse_addons' module is not installed or is installed incorrectly.
fix
Install the module using pip: 'pip install argparse-addons'.
TypeError: '>' not supported between instances of 'str' and 'int'
Comparing a string argument to an integer without converting the string to an integer first.
fix
Convert the argument to an integer before comparison: 'if int(args.detect_mode) > 1:'.
argparse.ArgumentError: argument --foo: conflicting option string: --foo
Defining two arguments with the same option string in argparse.
fix
Ensure each argument has a unique option string in the ArgumentParser definition.
argparse.ArgumentTypeError: invalid int value: 'net_model'
Providing a non-integer value for an argument expected to be an integer.
fix
Ensure that the value provided for the argument is a valid integer.
SyntaxError: invalid syntax
Using f-string syntax in a Python version that does not support it.
fix
Upgrade to Python 3.6 or later, or use an alternative string formatting method.
Upgrade
Version history
0.12.0latest on PyPI · released Jan 29, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
argparse-addons — pip install argparse-addons · libregistry