Interview Prep/Python for DevOps/OS, filesystem, subprocess & CLIs

Why might you choose `click` (or `typer`) over `argparse`?

IntermediateConceptOS, filesystem, subprocess & CLIs
Answer

click gives decorators for options and commands, nested command groups, envvar= defaults, type=click.Choice([...]) and click.Path(exists=True) validation, prompts and confirmation (@click.confirmation_option), colored output, and click.testing.CliRunner for tests without spawning processes. typer builds on click using type hints.

@click.command()
@click.option("--region", envvar="AWS_REGION", required=True)
@click.option("--dry-run/--no-dry-run", default=True)
def main(region, dry_run): ...

Trade-off: a third-party dependency, which matters for scripts dropped onto bare servers.

All Python for DevOps questions Roadmap: Python for automation

More on OS, filesystem, subprocess & CLIs