![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
configurable-argparse-DavidRodriguezSoaresCUI
Advanced tools
Argparse-based way of CLI argument handling boosted by YAML reusable configurations
When writing a command-line Python script that needs to take many arguments, usability issues may arise:
Configurable argparse aims at offloading the "noise" (often used argument configurations) into "recipes" that can be reused, while retaining the ability to override what needs to be adapted (the "signal"), therefore giving the user an experience that allows to efficiently use the program.
This simple example is there show how to use configurable argparse and how it makes using
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'-t', '--nb_threads',
type: int, default=4,
help="Number of threads to use"
)
...
exclusive_group = parser.add_mutually_exclusive_group()
exclusive_group.add_argument(
'--verbose',
action='store_true',
help='Show all messages'
)
exclusive_group.add_argument(
'--quiet',
action='store_true',
help='Show no messages'
)
parser.parse_args()
...
def main():
args = get_args()
Usage example:
python example_program.py -t 4 --use_library=libabc --ignore=E123,E321 --add_src=/homes/user/documents/ --quality=0.65 --no_audio --quiet
In this example, if the user wants to change an argument from run to run, the difference is lost in the "noise".
ARGPARSE_PARSER_ARGS = {"prog": "Example program"}
ARGPARSE_ARGUMENTS = [
Argument(
('-t', '--nb_threads'),
{
'type': int,
'default': 4,
'help': "Number of threads to use"
}
),
...
ArgumentExclusiveGroup([
Argument(
'--verbose',
{
'action': 'store_true',
'help': 'Show all messages'
}
),
Argument(
'--quiet',
{
'action': 'store_true',
'help': 'Show no messages'
}
)
])
]
...
def main():
args = get_args(
parser_args=ARGPARSE_PARSER_ARGS,
arguments=ARGPARSE_ARGUMENTS,
yaml_config_base=Path(__file__)
)
Usage example:
python example_program.py -t 4 --use_library=libabc --ignore=E123,E321 --add_src=/homes/user/documents/ --quality=0.65 --no_audio --quiet
(save config as usual
)python example_program.py --use_config=usual --quality=0.55
In this example, if the user wants to change an argument from run to run, the difference is immediately apparent since the "noise" is abstracted away in a usual
configuration.
FAQs
Argparse-based way of CLI argument handling boosted by YAML reusable configurations
We found that configurable-argparse-DavidRodriguezSoaresCUI demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.