python-fire generate CLI for your python code

after pip install fire, you can use it in your code:

import fire
class Example(object):
    def hello(self, name='world'):
        """Says hello to the specified name."""
        return 'Hello {name}!'.format(name=name)
def main():
    fire.Fire(Example)
if __name__ == '__main__':
    main()

Test this example.py:
$ ./example.py hello
Hello world!
$ ./example.py hello David
Hello David!
$ ./example.py hello --name=Google
Hello Google!

Leave a Reply

Your email address will not be published. Required fields are marked *