4 ms·
if you want complex subcommands and a truly fluent CLI interface, go with a click. https://click.palletsprojects.com/ https://click.palletsprojects.com/ else:
by fforflo 2y ago
if you want complex subcommands and a truly fluent CLI interface, go with a click. https://click.palletsprojects.com/ https://click.palletsprojects.com/
else: argparse is more than enough https://docs.python.org/3/library/argparse.html https://docs.python.org/3/library/argparse.html
- amlozano 2y agoOr go a step beyond and get typer (which builds on click IIRC) https://typer.tiangolo.com/ https://typer.tiangolo.com/ If you use Poetry and a pyproject.toml, you can even make your package installable with something like pipx straight from Github. Its a trick I use often for little command line utilities. https://python-poetry.org/docs/pyproject/#scripts https://python-poetry.org/docs/pyproject/#scripts
- kstrauser 2y agoI've not personally stumbled on a UI where Click was used to make something nicer than argparse could. I'm not saying those don't exist, just that I haven't seen one. Every time I've seen someone use Click at work, it was to implement some simple args that argparse could handle identically. "Why are we using Click here?" "Because it's nice!" "In what way?" "It's nice!" "But we're not actually using the nice parts." "Click is nice!" Click is nice. IMO it's used way too often in cases where argparse would do just as well.
- noitpmeder 2y agoI've reached for click when I need to create a layered command scheme .. ex where `mytool command1 --help` and `mytool command2 --help` would provide two different sets of arguments. Similar to what the `git` suite provides.
- kstrauser 2y agoThe argparse version of that is `add_subparsers`: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_subparsers https://docs.python.org/3/library/argparse.html#argparse.Arg...