Last modified: Aug 11, 2025 By Alexander Williams
Python Typer Commands: Single vs Multi
Python Typer is a library for building CLI apps. It is simple and intuitive. This article explains single and multi-command apps.
What Is Typer?
Typer helps create command-line interfaces easily. It uses Python type hints. It is built on top of Click.
If you are new to Typer, check our guide on how to install Typer in Python.
Single-Command Apps
A single-command app performs one task. It is the simplest Typer application. The function becomes the CLI command.
Here is an example of a single-command app:
import typer
def greet(name: str):
typer.echo(f"Hello, {name}!")
if __name__ == "__main__":
typer.run(greet)
Run the script with a name argument:
python script.py John
The output will be:
Hello, John!
This is a basic single-command app. The greet
function is the command.
Multi-Command Apps
Multi-command apps have multiple subcommands. They are useful for complex CLI tools. Each subcommand performs a different task.
Here is an example of a multi-command app:
import typer
app = typer.Typer()
@app.command()
def greet(name: str):
typer.echo(f"Hello, {name}!")
@app.command()
def farewell(name: str):
typer.echo(f"Goodbye, {name}!")
if __name__ == "__main__":
app()
Run the script with different commands:
python script.py greet John
python script.py farewell John
The outputs will be:
Hello, John!
Goodbye, John!
This app has two commands: greet
and farewell
. Each command is defined using @app.command()
.
Key Differences
Single-command apps are simple. They have one function. Multi-command apps are more flexible. They support multiple functions.
Use single-command apps for simple tasks. Use multi-command apps for complex tools. Multi-command apps are better for organizing code.
Adding Help Text
Typer automatically generates help text. You can add descriptions for better clarity.
Here is an example with help text:
import typer
app = typer.Typer(help="A simple greeting app.")
@app.command(help="Greet someone.")
def greet(name: str):
typer.echo(f"Hello, {name}!")
@app.command(help="Say goodbye.")
def farewell(name: str):
typer.echo(f"Goodbye, {name}!")
if __name__ == "__main__":
app()
Run the script with --help
:
python script.py --help
The output will show the help text:
Usage: script.py [OPTIONS] COMMAND [ARGS]...
A simple greeting app.
Options:
--help Show this message and exit.
Commands:
farewell Say goodbye.
greet Greet someone.
Conclusion
Typer makes CLI app development easy. Single-command apps are great for simple tasks. Multi-command apps offer more flexibility.
Choose the right type based on your needs. For more details, see our guide on installing Typer.