Same CLI built with Click and Typer — see which one wins forever.
Type hints • Auto docs • 70% less code • Built by FastAPI creator
import click
@click.command()
@click.option('--name', required=True, help='Your name')
@click.option('--age', type=int, help='Your age')
@click.option('--shout', is_flag=True, help='Shout the message')
def hello(name: str, age: int | None, shout: bool):
"""Simple greeting CLI"""
msg = f"Hello {name}!"
if age:
msg += f" You are {age} years old."
if shout:
msg = msg.upper() + "!!!"
click.echo(msg)
if __name__ == '__main__':
hello()
#!/usr/bin/env python
import typer
app = typer.Typer(help="Simple greeting CLI")
@app.command()
def hello(
name: str = typer.Option(..., "--name", help="Your name"),
age: int | None = typer.Option(None, "--age", help="Your age"),
shout: bool = typer.Option(False, "--shout", help="Shout the message")
):
"""Simple greeting CLI"""
msg = f"Hello {name}!"
if age:
msg += f" You are {age} years old."
if shout:
msg = msg.upper() + "!!!"
typer.echo(msg)
if __name__ == "__main__":
app()
| Feature | Click | Typer | Winner |
|---|---|---|---|
| Type Hints | No (manual) | Native | Typer |
| Code Length | ~30 lines | ~18 lines | Typer |
| Auto Documentation | Basic | Perfect (like FastAPI) | Typer |
| Async Support | Hard | Native | Typer |
| Created By | Pallets (Flask team) | Sebastián Ramírez (FastAPI) | Typer |
| Future-Proof | Mature but aging | Modern Python | Typer |
Use Typer for all new projects. Click only for legacy.