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

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.



I recently wrote this (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.


There is also Typer[1]

[1] https://github.com/tiangolo/typer


Similar interface, different design goals. This lib has 6x the code, dependencies, and isn't as easy to vendor/audit.


Yep, good work! Though I do think the name "clii" could generate some confusion. Maybe not though.


Thanks!


Does it handle help automatically? If not, and you think that'd be a valuable addition, I would like to take a crack at implementing it :)

What I mean is if you execute script.py help, it will print out the possible options, along with their docstrings, or maybe just the first line.


It does parse docstrings in a very basic way (https://github.com/jamesob/clii#help-text-from-docstrings) but if you end up hacking in something you want, PRs are welcome.


You really nailed this, imho. Awesome work.

What is the reason for requiring Python >=3.7?


Thanks. That's a really good point - maybe it's usable on earlier versions. Can't remember why I thought otherwise, will have to test.


This looks really good actually - bullshit-minimising. Will check it out.


I personally enjoy using 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.


Fire 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...


I concur. I've found argparse to be more straightforward and also has the benefit of being part of python itself.


Click 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.


Configargparse is a great drop in replacement for argparse that I use to handle bridging env vars with cli flags

https://pypi.org/project/ConfigArgParse/


YES I need this in my life! Tried searching for such a thing but I guess had the wrong keywords.


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


absl.flags[1] is another pretty good option.

[1] https://abseil.io/docs/python/guides/flags




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

Search: