Hacker News new | past | comments | ask | show | jobs | submit login
Python Fire: a library for automatically generating command line interfaces (googleblog.com)
32 points by nafizh on March 4, 2017 | hide | past | favorite | 10 comments

Convenient. I especially like that it has a completion-helper.

The docs seem to go to great lengths to not state this clearly, but it works fine on bare functions too:

    import fire

    def test(a="yes"):
      print "a: " + a


    $ python example.py
    a: yes
    $ python example.py no
    a: no
    $ python example.py --a maybe
    a: maybe

I wonder whose problems this solves.

I have a handful of scripts with miniscule CLI handling (usually len(sys.argv) is enough) - so it's 3 loc instead of 5?

Then I have a moderate amount of scripts where using click or optparse makes sense. Just looked up one tool, there's exactly 12 lines (including import, ignoring linebreaks) to handle 6 different CLI args. I could use fire. Less code, more "magic", less self-documenting excplicit code

Then there's this application with 15 @click.option() lines (don't ask, ran out of sensible single-char argument shorthands). Yes, it has an ugly main() with 15 keyword arguments, but I'd also have that with fire I guess. but here at least it's explicit again.

TLDR: Sounds absolutely nice on first skim, but I don't see why I would ever use this. Have I been writing so many CLI apps in python already that I exhibit stockholm syndrome towards click AND optparse? :)

An excellent question. Certainly switching from argparse to Fire will usually only save you some small amount of code.

But if your code is changing, that's when you'll start to see larger time savings. With Fire, your CLI will stay up to date without you having to update any parsing code.

I've lately come to know and respect argparse. Click is nice and great, but can present an unnecessary burden if your script uses (intentionally or not) no other dependencies outside the standard library. And optparse is deprecated in Python 3.

Oh yes, I'm strictly a Python 2 user (I know, I know).

Some libraries just seem obvious in retrospect. This looks very cool. I've had a lot of success using click for command line programs in the past. Fire looks like it'd replace click for the majority of simple cli programs I write.

Looks pretty good. But if you're going to open source it, you might as well make it a proper Python project and conform to style guides (Google's own for one). This one has all the tests in the same directory as other files instead of a 'tests' directory, it's missing requirements.txt and method names start with upper case.

Looks great! Very intuitive. This is something I could actually see myself using instead of argparse; and being able to generate a CLI from a third party object is amazing!

Looks fantastic. Argparse isn't hard to use, but it's a lot of boilerplate. I'll be happy not to have to deal with it again.

You may want to give a try to docopt

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