6 ms·
I have to say, at first blush I would not choose click over argparse. I do have to look up the docs of argparse every time I use it, but I like that it's just g
by tgb 6y ago
I have to say, at first blush I would not choose click over argparse. I do have to look up the docs of argparse every time I use it, but I like that it's just gives me the args and lets me structure the program flow how I want to, which I think is more natural.
And then I can do things like import a big package (pandas) only after parsing the args, which is highly convenient to users that want to check the argument options without a five second lag.
- empthought 6y agoI agree; click's approach is like some kind of old-school 4GL that tries to automatically create GUI elements from your database tables, except mapping CLI to functions in your modules. People should be putting enough thought into their CLI that Click doesn't really help them much.
- i3winner 6y agoI concur. I've found argparse to be more straightforward and also has the benefit of being part of python itself.
- kortex 6y agoClick has one feature which is huge for me: parsing env variables following some pattern eg MYAPP_FOO. For lazy import - You can do it with click, too, just put your imports in your entrypoint functions. Click isn't minimalistic though. Nor is poetry or pyenv. Seems to be the main complaints about the article.
- jabwork 6y agoConfigargparse is a great drop in replacement for argparse that I use to handle bridging env vars with cli flags https://pypi.org/project/ConfigArgParse/ https://pypi.org/project/ConfigArgParse/
- kortex 6y agoYES I need this in my life! Tried searching for such a thing but I guess had the wrong keywords.
- jobeirne 6y agoI recently wrote this (https://github.com/jamesob/clii https://github.com/jamesob/clii) because I can't stand click and got sick of having to check the argparse docs every time I wanted to write a CLI. I guarantee you'll spend a tenth of the time trying to figure out how to use this thing, it has no dependencies, and is implemented in a single vendor-friendly file.
- darkteflon 6y agoThis looks really good actually - bullshit-minimising. Will check it out.
- fastball 6y agoThere is also Typer[1] [1] https://github.com/tiangolo/typer https://github.com/tiangolo/typer
- tboerstad 6y agoYou really nailed this, imho. Awesome work. What is the reason for requiring Python >=3.7?
- 6y ago
- fabioz 6y agoI personally enjoy using https://github.com/google/python-fire https://github.com/google/python-fire nowadays. -- it's probably not the most flexible tool, but IMHO it's the one with the best API: fire.Fire(obj) and everything else is taken care of ;) p.s.: for lazy imports, just don't put them in the top of your module in the entry point.
- minimaxir 6y agoFire plays nice with package entry_points as well. Here's a very minimal CLI for one of my PyPI packages: https://github.com/minimaxir/aitextgen/blob/master/aitextgen/cli.py https://github.com/minimaxir/aitextgen/blob/master/aitextgen...
- alexhutcheson 6y agoabsl.flags[1] is another pretty good option. [1] https://abseil.io/docs/python/guides/flags https://abseil.io/docs/python/guides/flags