Python Fire – Generates CLIs from any Python object
github.com
github.com
Hope you find Fire useful!
What's next for Python Fire? We're working on improving the help screens and usage outputs so it feels less like a developer tool and more like a professional grade CLI. So stay tuned as it gets better!
This caused me to have to remove `fire` from a project repo's requirements.txt so that ipython wouldn't be included in production builds. Then in the testing script that used it, there was a comment saying "you're going to need ipython for this"
Here's a decent example of this https://github.com/pytorch/examples/blob/master/imagenet/mai...
def train(
data: File,
arch='resnet18',
workers=4,
epochs=90,
start_epoch=0,
batch_size=256,
learning_rate=0.9,
momentum=1e-4,
):
...
that could be exposed as a cli if __name__ is main but otherwise can be imported in a notebook or another script. cat > cli.pl6
#| Duplicates without frobnication
multi sub MAIN( 'duplicate', Int $times, Str $text ) {
say $text x $times;
}
#| Frobnicates up to a limit
multi sub MAIN('frobnicate', Int :$length = 24, Bool :v(:$verbose))
{
say 'Verbosity ', ($verbose ?? 'on' !! 'off');
}
perl6 cli.pl
Usage:
cli.pl6 duplicate <times> <text> -- Duplicates without frobnication
cli.pl6 [--length=<Int>] [-v|--verbose] frobnicate -- Frobnicates up to a limit
perl6 cli.pl6 duplicate 3 blah...
blah...blah...blah...I never have to think about the "CLI" when using click, everything "just works"...
My only frustrations are a missing default handler for --version, and that I can't use argument names colliding with builtins such as 'input'. All the flexibility of argparse without boilerplate.
Seeing another library that makes it easier to access things from the command line is awesome, and finding that there are even more I didn't know about in the comments is even better.
I think it would be really nice to have a library that takes the type annotated functions and lets you expose them as a CLI, GUI, REST API and a web form. Practically just combining click, flask, rest framework and Gooey. Would be a great tool for data scientists.
Take something like
def recognize(image: Image) -> List[Prediction]
preds = model(image)
return preds
and generate web page that lets you drop an image in and get a list of predictions:)
https://github.com/chriskiehl/Gooey
That'll be neat.
On the latter part, nah, not really. Gooey builds all of its widgets internally. There has been some interest in Gooey exposing the little pre-baked components it uses as a util library, but I haven't explored the option super deeply
it is bounds better than argparse and click. would highly recommend.
important to note here, that a lot of this is thanks to the python team's continued extension of the inspect module.
Luigi [1] does something similar, in that it auto-creates an API that lets you call any task in your task dependency graph, and provide parameters as arguments to flags. One of the things that made working with Luigi such a breeze (although we experienced other problems for our use cases).
I've never thought of something like this, but this would be very useful for many platforms.
Also, developing a Python library and not keeping the most basic standard (PEP8)? You should not be allowed near Python. I really have no better words for this, just fucking lazy. I hate lazy developers, because you are the reason most software is shit.