Post

Typer: Easily Building CLIs with Python

Tiangolo's library that turns Python functions into powerful command-line tools — with zero boilerplate.

Typer: Easily Building CLIs with Python

If you’ve ever tried to turn a Python script into a proper terminal tool, you know the pain: argparse verbosity, manual type handling, confusing help output… Typer solves all of that.

“Typer is like FastAPI, but for CLIs. Declare your types, and it handles the rest.”

What is Typer?

Typer is a library created by Sebastián Ramírez (the same author behind FastAPI) that lets you build command-line interfaces using nothing but Python type hints. No verbose configuration, no complicated decorators.

It uses Click under the hood, but elevates the experience significantly: automatic validation, auto-generated help, shell autocompletion, and support for subcommands — all out of the box.


Installation

1
2
3
4
5
# Basic installation
pip install typer

# With recommended extras (colors, autocompletion)
pip install "typer[all]"

Requires Python 3.7+ and works with poetry, uv, or any virtual environment.


Basic Usage

Your first CLI in under 10 lines:

1
2
3
4
5
6
7
8
9
10
11
12
import typer

app = typer.Typer()

@app.command()
def greet(name: str, times: int = 1):
    """Greet someone N times."""
    for _ in range(times):
        typer.echo(f"Hello, {name}!")

if __name__ == "__main__":
    app()

Run it from the terminal:

1
2
3
4
5
# Direct usage
python main.py Alice --times 3

# Auto-generated help
python main.py --help

Typer generates the command documentation from the docstring and type hints. No extra work required.


Use Cases

Typer shines across a wide range of contexts:

ContextUse Cases
🔧 Dev ToolsScaffolding, migrations, internal linters
🚀 Deploy & OpsCI/CD scripts, infrastructure management
📊 Data ScienceRunning experiments, processing datasets
📦 Python PackagesShip your library with a built-in CLI

Conclusion

Typer is the most elegant and productive way to build CLIs in Python today. If you already know FastAPI, the learning curve is almost flat. And if you don’t, you’ll be surprised by how little code you need to build a robust, well-documented terminal tool.

📖 Official docs: typer.tiangolo.com
🐙 Repository: github.com/tiangolo/typer

This post is licensed under CC BY 4.0 by the author.