Notepad/enter/Coding Tips (Classical)/Terminal Tips/2. CLI Tools/Languages/Python/Fire.md

559 B

Python fire is extremely useful for automatically generating command line interfaces (CLIs) from absolutely any Python object.

Examples:

The python class:

import fire

class Calculator(object):
  """A simple calculator class."""

  def double(self, number):
    return 2 * number

if __name__ == '__main__':
  fire.Fire(Calculator)

Then, when calling the file on the terminal, the CLI is already there:

python calculator.py double 10  # 20
python calculator.py double --number=15  # 30