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:

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:

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!

Tutorial

Build Command-Line Interfaces With Python's argparse

In this step-by-step Python tutorial, you'll learn how to take your command-line Python scripts to the next level by adding a convenient command-line interface (CLI) that you can write with the argparse module from the standard library.

intermediate python stdlib

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


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