Skip to content

Instantly share code, notes, and snippets.

@dylanroy
Last active October 2, 2020 22:25
Show Gist options
  • Save dylanroy/f4c68b1db97fa980577e51f0c808122d to your computer and use it in GitHub Desktop.
Save dylanroy/f4c68b1db97fa980577e51f0c808122d to your computer and use it in GitHub Desktop.
Python CLI Library Showdown
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("name", help="The person to greet.", type=str)
args = parser.parse_args()
print(f"Hello {args.name}!")
Library Time Saving Simplicity Flexibility Dependencies Support Total
Fire 10 10 2 5 7 0
Click 10 9 7 6 7 0
Typer 10 9 8 5 6 0
argparse 5 8 6 10 10 0
optparse 5 8 6 10 10 0
sys.argv 3 10 3 10 10 0
import click
@click.command()
@click.option("--name", prompt="Your name", help="The person to greet.")
def hello(name):
click.echo(f"Hello {name}!")
if __name__ == '__main__':
hello()
import fire
def hello(name="World"):
return f"Hello {name}!"
if __name__ == '__main__':
fire.Fire(hello)
import sys
def main():
name = sys.argv[1] if sys.arg[1] else 'World'
print(f"Hello {name}!")
if __name__ == "__main__":
main()
import sys
def main():
name = sys.argv[1] if len(sys.argv) > 1 else "World"
print(f"Hello {name}!")
if __name__ == "__main__":
main()
import typer
def main(name: str):
typer.echo(f"Hello {name}!")
if __name__ == "__main__":
typer.run(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment