Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

if you want complex subcommands and a truly fluent CLI interface, go with a click. https://click.palletsprojects.com/

else: argparse is more than enough https://docs.python.org/3/library/argparse.html



Or go a step beyond and get typer (which builds on click IIRC)

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


What value does poetry add to this? A simple cli should be trivially packageable.


Just any properly packaged Python project is installable from git by pip. No deps needed.


I'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.


I'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.


The argparse version of that is `add_subparsers`: https://docs.python.org/3/library/argparse.html#argparse.Arg...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: