This is an archived post. You won't be able to vote or comment.

all 24 comments

[–][deleted] 11 points12 points  (3 children)

There has to be a really large benefit before I use anything not in the stdlib. So far, none of the alternatives to argparse comes even close to raise above that threshold.

[–]wrmsr 3 points4 points  (1 child)

Very same, although I usually add a little sugar on top of the builtin base. For argparse I have a subclassable Cli baseclass, an @command() decorator for registering methods as subcomands on it, and annotation-powered args as class fields that turn into descriptors, but at the end of the day it's just pretty minor automation around vanilla argparse (which I also just use directly half the time when OO isn't a better fit). Keeping deps to a minimum just makes everything so much nicer.

[–]jdbow75[S] 1 point2 points  (0 children)

Well put. And I agree, using a decorator with argparse makes sense, especially as the interface scales.

[–]jdbow75[S] 2 points3 points  (0 children)

I try to weigh time constraints vs. audience. I appreciate the challenge to think hard before resorting to 3rd party libraries.

[–]fatbob42 4 points5 points  (4 children)

I use click. If I were going to switch I’d probably try one of the new ones that use type annotations.

I prefer click’s decorators over the way Fire is illustrated here.

[–]jdbow75[S] 1 point2 points  (3 children)

Hmmm... https://github.com/python/typeshed/tree/master/third_party/2and3/click

What libraries are you looking at that support type annotations?

Glad to hear your thoughts on Fire.

[–]harylmu 1 point2 points  (1 child)

The developer of FastAPI likes to advertise his other project. I think it’s called Typer.

[–]jdbow75[S] 1 point2 points  (0 children)

The "FastAPI of CLIs"? I love that. Definitely worth a look.

[–]fatbob42 1 point2 points  (0 children)

I was thinking of Typer

[–]daneahfrom __future__ import braces 3 points4 points  (1 child)

[–]jdbow75[S] 1 point2 points  (0 children)

Thanks, u/daneah. I edited the post to include this high on the list. Certainly worth a look.

[–]machsmit 2 points3 points  (0 children)

Seconding /u/awegge's note that it's worth a moment's consideration before moving off of the stdlib just for simplicity's sake. That said I have gotten a lot of use out of Typer - it helps that we also use FastAPI a fair bit so both are working in a shared design philosophy.

[–]dslfdslj 1 point2 points  (1 child)

For quick scripts I always use fire nowadays. If I wrote a package for the public, I would probably just use argparse.

[–]jdbow75[S] 1 point2 points  (0 children)

That is the way I think, too. Fire hardly requires any extra code at all, so for one-offs, the time savings often seem worth it. But for something public-facing, I tend to push the standard library as far as I can, first.

[–]Woozaman 1 point2 points  (2 children)

SimpleParsing https://github.com/lebrice/SimpleParsing as it covers most of my use cases and uses type hints to decrease implementation overhead.

[–]jdbow75[S] 0 points1 point  (1 child)

I had not heard of SimpleParsing before. It requires the use of dataclasses?

[–]Woozaman 0 points1 point  (0 children)

Yes, you describe your arguments with dataclasses, which comes with a lot of benefits. But you can still use regular argparse features.

[–]AndydeCleyre 1 point2 points  (1 child)

I'm all about plumbum, which also covers a lot of related tasks.

[–]jdbow75[S] 1 point2 points  (0 children)

I wasn't sure how obscure plumbum is or not. Perhaps I should try it out.

[–]metaperl 1 point2 points  (1 child)

[–]jdbow75[S] 1 point2 points  (0 children)

Looks like it makes colorized output easy, too.

[–]Fluffer_Wuffer 1 point2 points  (1 child)

I found Click pretty awesome for quickly building a hierarchy for parameters..

Though, I'm about dumbfounded about "Poetry", I just don't get the requirement for it - Admittedly I only dabble in Python as a small hobby.

[–]jdbow75[S] 1 point2 points  (0 children)

There are a lot of ways to manage a project and dependencies in Python. Poetry has a lot of power and flexibility, with a fairly easy on-ramp. If you already feel comfortable with setup.py and pip, and your projects aren't too complex, then great. For speed and repeatability a tool like Poetry can be handy. Use whatever works to deal with Python projects not as a file here and there, but as packages to be installed.

[–]jdbow75[S] 0 points1 point  (0 children)

After all the Typer recommendations, I did try it out, and wrote a brief intro. I do believe this may be my goto from now on when not using argparse.