Last active
October 2, 2020 22:25
-
-
Save dylanroy/f4c68b1db97fa980577e51f0c808122d to your computer and use it in GitHub Desktop.
Python CLI Library Showdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fire | |
def hello(name="World"): | |
return f"Hello {name}!" | |
if __name__ == '__main__': | |
fire.Fire(hello) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def main(): | |
name = sys.argv[1] if sys.arg[1] else 'World' | |
print(f"Hello {name}!") | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Medium Post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def main(): | |
name = sys.argv[1] if len(sys.argv) > 1 else "World" | |
print(f"Hello {name}!") | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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