Skip to content

command-line interface (CLI)

A command-line interface (CLI) is a text-based method of interacting with a program by typing commands into a terminal or console. Unlike a graphical user interface (GUI), which relies on visual elements like windows, buttons, and menus, a CLI accepts text input and returns text output. Users type exact commands, so they control precisely what a program does.

In Python, you can build CLIs for your scripts and applications using the standard library module argparse, or third-party libraries like Click and Typer. These tools let you define commands, options, and arguments that users can pass when running a script from the terminal.

CLIs are especially useful for creating developer tools and automation scripts because they support scripting and pipelines.

Example

A minimal CLI built with argparse:

Language: Python
>>> import argparse

>>> parser = argparse.ArgumentParser(description="Greet someone")
>>> _ = parser.add_argument("name", help="name to greet")
>>> args = parser.parse_args(["Pythonista"])

>>> print(f"Hello, {args.name}!")
Hello, Pythonista!

Running the same script from the terminal:

Language: Shell
$ python greet.py --help
usage: greet.py [-h] name

Greet someone

positional arguments:
  name        name to greet

options:
  -h, --help  show this help message and exit

$ python greet.py Pythonista
Hello, Pythonista!
Build a Command-Line To-Do App With Python and Typer

Tutorial

Build a Command-Line To-Do App With Python and Typer

In this step-by-step project, you'll create a to-do application for your command line using Python and Typer. While you build this app, you'll learn the basics of Typer, a modern and versatile library for building command-line interfaces (CLI).

intermediate projects testing tools

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Dan Bader • Updated Oct. 19, 2026 • Reviewed by Leodanis Pozo Ramos