Clear and readable help text is essential for command-line applications. Before Python 3.14, the argparse module produced plain, monochrome help output, which could make longer option lists harder to read.
Since Python 3.14, the argparse includes built-in support for colored help text, improving the readability of CLI documentation without the need for third-party libraries. This feature is enabled by default when the terminal supports color, and it highlights elements such as option flags, metavariables, and section headers.
Consider a simple command defined with argparse:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose output')
parser.parse_args()
When you request the help message:
python main.py --help
Since Python 3.14, the output is automatically colorized. Option names and headings are displayed using ANSI colors, improving readability and making important parts stand out at a glance.
In some situations - such as logging, running in CI pipelines, or working in terminals that don't handle colors well - you may want to turn off colored output.
Python follows the widely adopted NO_COLOR convention for this purpose. Setting the environment variable disables colors.
NO_COLOR=1 python main.py --help
With this variable set, argparse falls back to plain text output, even if the terminal supports color.
You can also control this behavior directly in code. Since Python 3.14, the ArgumentParser constructor accepts a color parameter.
import argparse
parser = argparse.ArgumentParser(color=False)
parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose output')
parser.parse_args()
This ensures consistent, non-colored output regardless of environment variables or terminal capabilities.
Leave a Comment
Cancel reply