Easy Python CLI with Click
codingwithricky.com
Easy Python CLI with Click
1–10 of 64 posts
Re: Easy Python CLI with Click
#2Re: Easy Python CLI with Click
#3Re: Easy Python CLI with Click
#4Re: Easy Python CLI with Click
#5I've used Fire[0] for a few projects and have been meaning to give Click a try, but I'm not sure I like the syntax after reading through the article (holy moly decorators). Seems unwieldy to me, but does anyone have experience with both? [0] https://github.com/google/python-fire
Re: Easy Python CLI with Click
#6Re: Easy Python CLI with Click
#7Re: Easy Python CLI with Click
#8Does this do anything that the builtin argparse library https://docs.python.org/3/library/argparse.html doesn't? Seems it just turns it into decorator syntax.
Plus it comes with some useful utilities you might need in a cli to show a progressbar, display color, open test in a pager/an editor etc.
The official doc is really nice and gives it more justice than this blog post: https://click.palletsprojects.com/en/7.x.
Re: Easy Python CLI with Click
#9 def hello(name):
return "hello {}".format(name)
def ping():
return "pong"
if __name__ == "__main__":
import argh
parser = argh.ArghParser()
parser.add_commands([hello, ping])
parser.dispatch()Re: Easy Python CLI with Click
#10The thing that bugs me about click is that now your python script has a python dependency that you have to install every time you need to run the script. This is fine sometimes, but a lot of the time I want a script that will be usable with minimal setup, which is why I always use argparse, which is in the standard library, and gets the job done despite its quirky API.
In any case, comparing a stdlib library to a 3rd party one is a bit apples to oranges. Most people first decide whether or not they want to use pypi packages, and then start evaluating which ones are appropriate.