argparse and command-line scripts

Turning a script into a proper command with options and --help.

Also called: CLI, sys.argv, click, typer

Type
Term
Source
General
Language
Python

Example

Thanks to argparse, import.py --help lists every option of the script.

In code

import argparse
p = argparse.ArgumentParser(description="Import listings")
p.add_argument("file")
p.add_argument("--dry-run", action="store_true")
args = p.parse_args()

python import.py listings.csv --dry-run

Related terms

Added 2026-11-30 · Last reviewed 2026-11-30