GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add colour to `argparse` help · Issue #130645 · python/cpython

Add colour to argparse help #130645

New issue
Copy link
New issue
Copy link
Closed
Closed
Add colour to argparse help#130645
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@hugovk
hugovk
opened on Feb 27, 2025
Issue body actions

Feature or enhancement

In Python 3.13 we added colour output to the new REPL, traceback and doctest, and in 3.14 to unittest, test.regrtest and calendar, that can also be controlled with the PYTHON_COLORS, NO_COLOR and FORCE_COLOR environment variables:

  • https://docs.python.org/3.14/whatsnew/3.14.html#unittest
  • https://docs.python.org/3.14/using/cmdline.html#using-on-controlling-color

Let's add colour to argparse help output.

Survey

First, here's a survey of some other CLIs that use colour:

Survey
uv
Image Image
cargo
Image Image
composer
Image Image
ruff
Image Image
lsd
Image Image
fd
Image Image

See also: bat, hyperfine, oxipng, zizmor

gh
Image Image
rich-cli
Image Image
typer
Image Image

These fall into four groups:

  • uv/cargo: green + cyan
  • composer: yellow + green
  • ruff/lsd/fd/gh: only bold
  • typer/rich-cli: green + cyan + yellow

Prototypes

I've made prototypes of two of these (uv/cargo style, typer/rich-cli style), and another with blue + magenta similar to the 3.13 REPL/traceback.

Prototypes
main
Image Image
uv/cargo style
Image Image
typer/rich-cli style
Image Image
REPL style
Image Image

I think I prefer the typer/rich-cli style: the extra colour makes it easier to pick out the (green) short options from the (cyan) long options, and from their (green) arguments. And it should also be somewhat familiar to Python users who have used typer-based CLIs.

Linked PRs

  • gh-130645: Add colour to argparse help #132323
  • gh-130645: Add color to stdlib argparse CLIs #133380
  • GH-130645: Default to color help in argparse #136809
  • [3.14] GH-130645: Default to color help in argparse (GH-136809) #136886
Reacted by Tomas R., Adam Johnson, Hash, espdev, yihong, impervius and sedrubal
Reacted by Bryan Kaplan
Reacted by Sebastian Pipping and Erik Körner

Activity

  1. hugovk
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    type-featureA feature request or enhancementA feature request or enhancement
    on Feb 27, 2025
  2. hugovk
    added this to Argparse issueson Feb 27, 2025
  3. rhettinger commented on Feb 27, 2025

    @rhettinger
    rhettinger
    on Feb 27, 2025
    Contributor
    More actions

    I don't think this should be done.

    Reacted by M. Kocher and Bryan Kaplan
    Reacted by espdev, Josh Niec, sedrubal and malucart
  4. StanFromIreland commented on Feb 27, 2025

    @StanFromIreland
    StanFromIreland
    on Feb 27, 2025
    Member
    More actions

    Image links don't work in the survey.

    I'd vote for REPL style. It's not bombarding you with color and the magenta/purple is generally visible in all terminal styles.

    Raymond could you please clarify why? We already have some color in the REPL and there are ongoing efforts to add more (#130472) so it seems people are generally in favor of color.

    Edit: Seeing it now, I think the simple ruff style would be fine, what do you think @rhettinger, about a very simple coloring?

    Reacted by Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి)
  5. hugovk commented on Feb 27, 2025

    @hugovk
    hugovk
    on Feb 27, 2025
    MemberAuthor
    More actions

    Image links don't work in the survey.

    Thanks, fixed.

  6. AlexWaygood commented on Feb 27, 2025

    @AlexWaygood
    AlexWaygood
    on Feb 27, 2025
    Member
    More actions

    Are you aware of the rich-argparse project (https://github.com/hamdanal/rich-argparse)? I use it in my typeshed-stats project, and it's very nice indeed. This is all I need to do to add colour to my argparse-based CLI in that project; everything else is just stdlib argparse.

    Reacted by M. Kocher and Maximilian Knespel
  7. sobolevn commented on Feb 28, 2025

    @sobolevn
    sobolevn
    on Feb 28, 2025
    Member
    More actions

    I think that adding an option (which is off by default) is a good idea, but argparse must stay colorless by default, too many tests in the wild depend on it.

    Reacted by Bryan Kaplan
  8. rhettinger commented on Mar 2, 2025

    @rhettinger
    rhettinger
    on Mar 2, 2025
    Contributor
    More actions

    If you end-up doing this over my objections (no major standard command-line tool does this), then it must be opt-in.

    Also, the bulk of the code should be in a separate submodule that is only imported with needed. Start-up time is a critical issue for argparse. We've worked hard to avoid dependencies and to have a fast load time.

    Also, the choice of colors really matters. Bad choices can impair usability for all users, or for users with the particular choice of light or dark backgrounds, or for users with vision issues including various kinds of color blindness. IPython is an example of a tool that made poor choices. When running ?? to look at source code against a black background, IPython displays operators like =, +, or parens in a dark blue that is very hard to read.

    AFACIT, no group of users has ever requested this feature even though this is a heavy used, popular module. ISTM that the OP is doing this as part of a "sweep" across modules (such as unittest) without considering the whether the existing users of the module want or need this.

    Reacted by Bryan Kaplan
  9. rhettinger commented on Mar 2, 2025

    @rhettinger
    rhettinger
    on Mar 2, 2025
    Contributor
    More actions

    Example of IPython's impaired readability with a poor choice of colors (the assignments, multiplications, and function calls are almost invisible and the docstring is challenging as well):

    Image
    Reacted by sobolevn and Maximilian Knespel
  10. hugovk commented on Mar 3, 2025

    @hugovk
    hugovk
    on Mar 3, 2025
    MemberAuthor
    More actions

    Are you aware of the rich-argparse project (hamdanal/rich-argparse)?

    I wasn't, thanks for sharing. I think this would still be useful in the stdlib, for when you want to keep your dependencies to a minimum, and rich (plus its dependencies) is a fairly large package.

    I think that adding an option (which is off by default) is a good idea, but argparse must stay colorless by default, too many tests in the wild depend on it.

    Yes, it can be opt-in. And the existing PYTHON_COLORS and NO_COLOR env vars can also be used.

    Start-up time is a critical issue for argparse. We've worked hard to avoid dependencies and to have a fast load time.

    Agreed, this is important.

    Also, the choice of colors really matters. Bad choices can impair usability for all users, or for users with the particular choice of light or dark backgrounds, or for users with vision issues including various kinds of color blindness. IPython is an example of a tool that made poor choices. When running ?? to look at source code against a black background, IPython displays operators like =, +, or parens in a dark blue that is very hard to read.

    Absolutely, colour choice and accessibility is important. This is why I've surveyed popular existing tools and picked colours with good contrast, and none of those or my suggestsions use that blue. And @ambv is adding theming support this month, see: #130472 (comment).

    AFACIT, no group of users has ever requested this feature even though this is a heavy used, popular module.

    Here's some people wanting colour help in argparse:

    • "In argparse, I've always wanted a way to make colored help text like those of poetry and pipenv." python/cpython#86189
    • "A drop-in replacement would be nice so I don't have to switch from argparse to something else in all my projects." Textualize/rich#2258
    • "I'd also like to know how to properly color the --help output with colorama." https://stackoverflow.com/questions/69980467/argparse-remove-whitespace-after-flags-in-help-and-colorizing-help-output-wit

    I think the use of colour in third-party CLI replacements and rich-argparse also points to a demand.

    ISTM that the OP is doing this as part of a "sweep" across modules (such as unittest) without considering the whether the existing users of the module want or need this.

    Yes, now that we added colour support in 3.13 for the REPL and tracebacks, I'm looking to see where else we can improve the experience over plain monochrome output. Colour can be extremely helpful. unittest is a great example: coloured pytest output has long been very useful for finding the error(s) in long test logs. And it's now much easier to find errors in our own CI logs since unittest and test.regrtest have colour output.

    Example of IPython's impaired readability with a poor choice of colors (the assignments, multiplications, and function calls are almost invisible and the docstring is challenging as well):

    This is a good example of poor colour choice, thanks. This blue won't be used. As it happens, IPython 9.0.0 was released on Friday with much improved colours!

    Image
    Reacted by Zachary Ware, Adam Johnson, Michiel W. Beijen, Maximilian Knespel and malucart
  11. savannahostrowski commented on Mar 3, 2025

    @savannahostrowski
    savannahostrowski
    on Mar 3, 2025
    Member
    More actions

    I'm +1 on this, if it's opt-in and ensures that we can ensure the startup time isn't impacted. In CLI tools that I've worked on in the past, we leaned heavily on the ANSI defined color presets when trying to guarantee accessibility/sufficient contrast.

    Reacted by Zachary Ware, CF Bolz-Tereick, Hugo van Kemenade, Adam Johnson and Łukasz Langa
  12. ambv
    added 2 commits that reference this issue on May 2, 2025

    gh-130645: Add color to `argparse` help (GH-132323)

    4701ff9

    gh-130645: Add color to stdlib argparse CLIs (gh-133380)

    4ac916a
  13. hugovk
    closed this as completedon May 7, 2025
  14. github-project-automation
    moved this to Doc issues in Argparse issueson May 7, 2025
  15. Pranjal095
    added 2 commits that reference this issue on Jul 12, 2025

    pythongh-130645: Add color to `argparse` help (pythonGH-132323)

    aead660

    pythongh-130645: Add color to stdlib argparse CLIs (pythongh-133380)

    d16d641
  16. savannahostrowski
    added a commit that references this issue on Jul 20, 2025

    GH-130645: Default to color help in argparse (#136809)

    acbe896
  17. miss-islington
    added a commit that references this issue on Jul 20, 2025

    pythonGH-130645: Default to color help in argparse (pythonGH-136809)

    0db8c61
  18. savannahostrowski
    added a commit that references this issue on Jul 20, 2025

    [3.14] GH-130645: Default to color help in argparse (GH-136809) (#136886

    17c5959
  19. taegyunkim
    added a commit that references this issue on Aug 4, 2025

    pythonGH-130645: Default to color help in argparse (python#136809)

    7373ba2
  20. Agent-Hellboy
    added a commit that references this issue on Aug 19, 2025

    pythonGH-130645: Default to color help in argparse (python#136809)

    e129bcb
  21. ppisar
    added a commit that references this issue on Sep 5, 2025

    Disable coloring in Python interpreter

    74335f4
  22. pkratoch
    added a commit that references this issue on Sep 8, 2025

    Disable coloring in Python interpreter

    5e5b655
  23. kumaraditya303
    added a commit that references this issue on Sep 9, 2025

    [3.14] pythonGH-130645: Default to color help in argparse (pythonGH-1…

    cb8d6b3
  24. dreirund commented on Jul 10, 2026

    @dreirund
    dreirund
    on Jul 10, 2026
    More actions

    It seems to me that coloured output of argparse --help output uses only one specific colour scheme which I cannot change.

    And that colour scheme is barely readable on light themed terminals (e.g. black text on white background).

    Setting environment varianle NO_COLOR to true does disable coloured output completetly and thus makes the output readable again, but that is not a good system wiede setting if colouring in general is wanted.

    Many software that I install just uses argparse and so the --help output is not really readable on light terminals.

    So I hereby need to be able to configure argparse's colour scheme by environment variables (or config file).
    Is that possible? I did not find documentation on this.

    If not, this is a feature request.

    Regards!

  25. savannahostrowski commented on Jul 14, 2026

    @savannahostrowski
    savannahostrowski
    on Jul 14, 2026
    Member
    More actions

    If the contrast is insufficient, that'd be a bug. We use ANSI color palette so things should adapt accordingly. Can you please file a new issue for this, since this is closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    • Argparse issues
      Status
      Doc issues
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.