rich-argparse


Namerich-argparse JSON
Version 1.4.0 PyPI version JSON
download
home_page
SummaryRich help formatters for argparse and optparse
upload_time2023-10-21 17:30:14
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords argparse help-formatter optparse rich
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # rich-argparse

![python -m rich_argparse](
https://github.com/hamdanal/rich-argparse/assets/93259987/ae4a4968-1008-4fcd-8131-7a90292a7f3f)

[![tests](https://github.com/hamdanal/rich-argparse/actions/workflows/tests.yml/badge.svg)
](https://github.com/hamdanal/rich-argparse/actions/workflows/tests.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/hamdanal/rich-argparse/main.svg)
](https://results.pre-commit.ci/latest/github/hamdanal/rich-argparse/main)
[![Downloads](https://img.shields.io/pypi/dm/rich-argparse)](https://pypistats.org/packages/rich-argparse)
[![Python Version](https://img.shields.io/pypi/pyversions/rich-argparse)
![Release](https://img.shields.io/pypi/v/rich-argparse)
](https://pypi.org/project/rich-argparse/)

Format argparse and optparse help using [rich](https://pypi.org/project/rich).

*rich-argparse* improves the look and readability of argparse's help while requiring minimal
changes to the code.

## Table of contents

* [Installation](#installation)
* [Usage](#usage)
* [Output styles](#output-styles)
  * [Colors](#customize-the-colors)
  * [Group names](#customize-the-group-name-format)
  * [Highlighting patterns](#special-text-highlighting)
  * ["usage"](#colors-in-the-usage)
  * [--version](#colors-in---version)
  * [Rich renderables](#rich-descriptions-and-epilog)
* [Subparsers](#working-with-subparsers)
* [Documenting your CLI](#generate-help-preview)
* [Third party formatters](#working-with-third-party-formatters) (ft. django)
* [Optparse](#optparse-support) (experimental)
* [Legacy Windows](#legacy-windows-support)

## Installation

Install from PyPI with pip or your favorite tool.

```sh
pip install rich-argparse
```

## Usage

Simply pass `formatter_class` to the argument parser
```python
import argparse
from rich_argparse import RichHelpFormatter

parser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)
...
```

*rich-argparse* defines equivalents to argparse's [built-in formatters](
https://docs.python.org/3/library/argparse.html#formatter-class):

| `rich_argparse` formatter | equivalent in `argparse` |
|---------------------------|--------------------------|
| `RichHelpFormatter` | `HelpFormatter` |
| `RawDescriptionRichHelpFormatter` | `RawDescriptionHelpFormatter` |
| `RawTextRichHelpFormatter` | `RawTextHelpFormatter` |
| `ArgumentDefaultsRichHelpFormatter` | `ArgumentDefaultsHelpFormatter` |
| `MetavarTypeRichHelpFormatter` | `MetavarTypeHelpFormatter` |

## Output styles

The default styles used by *rich-argparse* are carefully chosen to work in different light and dark
themes.

### Customize the colors

You can customize the colors in the output by modifying the `styles` dictionary on the formatter
class. *rich-argparse* defines the following styles:

```python
{
    'argparse.args': 'cyan',  # for positional-arguments and --options (e.g "--help")
    'argparse.groups': 'dark_orange',  # for group names (e.g. "positional arguments")
    'argparse.help': 'default',  # for argument's help text (e.g. "show this help message and exit")
    'argparse.metavar': 'dark_cyan',  # for metavariables (e.g. "FILE" in "--file FILE")
    'argparse.prog': 'grey50',  # for %(prog)s in the usage (e.g. "foo" in "Usage: foo [options]")
    'argparse.syntax': 'bold',  # for highlights of back-tick quoted text (e.g. "`some text`")
    'argparse.text': 'default',  # for descriptions, epilog, and --version (e.g. "A program to foo")
    'argparse.default': 'italic',  # for %(default)s in the help (e.g. "Value" in "(default: Value)")
}
```

For example, to make the description and epilog *italic*, change the `argparse.text` style:

```python
RichHelpFormatter.styles["argparse.text"] = "italic"
```

### Customize the group name format

You can change how the names of the groups (like `'positional arguments'` and `'options'`) are
formatted by setting the `RichHelpFormatter.group_name_formatter` which is set to `str.title` by
default. Any callable that takes the group name as an input and returns a str works:

```python
RichHelpFormatter.group_name_formatter = str.upper  # Make group names UPPERCASE
```

### Special text highlighting

You can [highlight patterns](https://rich.readthedocs.io/en/stable/highlighting.html) in the
arguments help and the description and epilog using regular expressions. By default,
*rich-argparse* highlights patterns of `--options-with-hyphens` using the `argparse.args` style
and patterns of `` `back tick quoted text` `` using the `argparse.syntax` style. You can control
what patterns are highlighted by modifying the `RichHelpFormatter.highlights` list. To disable all
highlights, you can clear this list using `RichHelpFormatter.highlights.clear()`.

You can also add custom highlight patterns and styles. The following example highlights all
occurrences of `pyproject.toml` in green:

```python
# Add a style called `pyproject` which applies a green style (any rich style works)
RichHelpFormatter.styles["argparse.pyproject"] = "green"
# Add the highlight regex (the regex group name must match an existing style name)
RichHelpFormatter.highlights.append(r"\b(?P<pyproject>pyproject\.toml)\b")
# Pass the formatter class to argparse
parser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)
...
```

### Colors in the `usage`

The usage **generated by the formatter** is colored using the `argparse.args` and `argparse.metavar`
styles. If you use a custom `usage` message in the parser, it will treated as "plain text" and will
**not** be colored by default. You can enable colors in user defined usage message through
[console markup](https://rich.readthedocs.io/en/stable/markup.html) by setting
`RichHelpFormatter.usage_markup = True`. If you enable this option, make sure to [escape](
https://rich.readthedocs.io/en/stable/markup.html#escaping) any square brackets in the usage text.

### Colors in `--version`

If you use the `"version"` action from argparse, you can use console markup in the `version` string:

```python
parser.add_argument(
    "--version", action="version", version="[argparse.prog]%(prog)s[/] version [i]1.0.0[/]"
)
```

Note that the `argparse.text` style is applied to the `version` string similar to the description
and epilog.

### Rich descriptions and epilog

You can use any rich renderable in the descriptions and epilog. This includes all built-in rich
renderables like `Table` and `Markdown` and any custom renderables defined using the
[Console Protcol](https://rich.readthedocs.io/en/stable/protocol.html#console-protocol).

```python
import argparse
from rich.markdown import Markdown
from rich_argparse import RichHelpFormatter

description = """
# My program

This is a markdown description of my program.

* It has a list
* And a table

| Column 1 | Column 2 |
| -------- | -------- |
| Value 1  | Value 2  |
"""
parser = argparse.ArgumentParser(
    description=Markdown(description, style="argparse.text"),
    formatter_class=RichHelpFormatter,
)
...
```
Certain features are **disabled** for arbitrary renderables other than strings, including:

* Syntax highlighting with `RichHelpFormatter.highlights`
* Styling with the `"argparse.text"` style defined in `RichHelpFormatter.styles`
* Replacement of `%(prog)s` with the program name

Arbitrary renderables are displayed "as is" except for long runs of empty lines that get truncated
to two empty lines following the behavior of argparse.

## Working with subparsers

Subparsers do not inherit the formatter class from the parent parser by default. You have to pass
the formatter class explicitly:

```python
subparsers = parser.add_subparsers(...)
p1 = subparsers.add_parser(..., formatter_class=parser.formatter_class)
p2 = subparsers.add_parser(..., formatter_class=parser.formatter_class)
```

## Generate help preview

You can generate a preview of the help message for your CLI in SVG, HTML, or TXT formats using the
`HelpPreviewAction` action. This is useful for including the help message in the documentation of
your app. The action uses the
[rich exporting API](https://rich.readthedocs.io/en/stable/console.html#exporting) internally.

```python
import argparse
from rich.terminal_theme import DIMMED_MONOKAI
from rich_argparse import HelpPreviewAction, RichHelpFormatter

parser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)
...
parser.add_argument(
    "--generate-help-preview",
    action=HelpPreviewAction,
    path="help-preview.svg",  # (optional) or "help-preview.html" or "help-preview.txt"
    export_kwds={"theme": DIMMED_MONOKAI},  # (optional) keywords passed to console.save_... methods
)
```
This action is hidden, it won't show up in the help message or in the parsed arguments namespace.

Use it like this:

```sh
python my_cli.py --generate-help-preview  # generates help-preview.svg (default path specified above)
# or
python my_cli.py --generate-help-preview my-help.svg  # generates my-help.svg
# or
COLUMNS=120 python my_cli.py --generate-help-preview  # force the width of the output to 120 columns
```

## Working with third party formatters

*rich-argparse* can be used with other formatters that **do not rely on the private internals**
of `argparse.HelpFormatter`. A popular example is [django](https://pypi.org/project/django) that
defines a custom help formatter that is used with its built in commands as well as with extension
libraries and user defined commands. To use *rich-argparse* in your django project, change your
`manage.py` file as follows:

```diff
diff --git a/my_project/manage.py b/my_project/manage.py
index 7fb6855..5e5d48a 100755
--- a/my_project/manage.py
+++ b/my_project/manage.py
@@ -1,22 +1,38 @@
 #!/usr/bin/env python
 """Django's command-line utility for administrative tasks."""
 import os
 import sys


 def main():
     """Run administrative tasks."""
     os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_project.settings')
     try:
         from django.core.management import execute_from_command_line
     except ImportError as exc:
         raise ImportError(
             "Couldn't import Django. Are you sure it's installed and "
             "available on your PYTHONPATH environment variable? Did you "
             "forget to activate a virtual environment?"
         ) from exc
+
+    from django.core.management.base import BaseCommand, DjangoHelpFormatter
+    from rich_argparse import RichHelpFormatter
+
+    class DjangoRichHelpFormatter(DjangoHelpFormatter, RichHelpFormatter):  # django first
+        """A rich-based help formatter for django commands."""
+
+    original_create_parser = BaseCommand.create_parser
+
+    def create_parser(*args, **kwargs):
+        parser = original_create_parser(*args, **kwargs)
+        parser.formatter_class = DjangoRichHelpFormatter  # set the formatter_class
+        return parser
+
+    BaseCommand.create_parser = create_parser
+
     execute_from_command_line(sys.argv)


 if __name__ == '__main__':
     main()
```

Now try out some command like `python manage.py runserver --help` and notice how the special
ordering of the arguments applied by django is respected by the new help formatter.

## Optparse support

*rich-argparse* now ships with experimental support for [optparse](
https://docs.python.org/3/library/optparse.html).

Import optparse help formatters from `rich_argparse.optparse`:

```python
import optparse
from rich_argparse.optparse import IndentedRichHelpFormatter  # or TitledRichHelpFormatter

parser = optparse.OptionParser(formatter=IndentedRichHelpFormatter())
...
```

You can also generated a more helpful usage message by passing `usage=GENERATE_USAGE` to the
parser. This is similar to the default behavior of `argparse`.

```python
from rich_argparse.optparse import GENERATE_USAGE, IndentedRichHelpFormatter

parser = optparse.OptionParser(usage=GENERATE_USAGE, formatter=IndentedRichHelpFormatter())
```

Similar to `argparse`, you can customize the styles used by the formatter by modifying the
`RichHelpFormatter.styles` dictionary. These are the same styles used by `argparse` but with
the `optparse.` prefix instead:

```python
RichHelpFormatter.styles["optparse.metavar"] = "bold magenta"
```

Syntax highlighting works the same as with `argparse`.

Colors in the `usage` are only supported when using `GENERATE_USAGE`.

Customizing the group name format is not supported. optparse uses Title Case format by default.

## Legacy Windows support

If your application still runs on legacy Windows versions (older than Windows 10), you'll need to
enable ANSI escape sequences by calling `colorama.init()` otherwise colors will be disabled:

```python
import argparse
import colorama
from rich_argparse import RichHelpFormatter

colorama.init()
parser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)
...
```
This is **not** required on Windows 10 and newer or on other operating systems.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "rich-argparse",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "argparse,help-formatter,optparse,rich",
    "author": "",
    "author_email": "Ali Hamdan <ali.hamdan.dev@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/7b/04/4b0b9b06662a4559041a88c2d31e93ecbc8aca1c45fee10a0c1a000b7274/rich_argparse-1.4.0.tar.gz",
    "platform": null,
    "description": "# rich-argparse\n\n![python -m rich_argparse](\nhttps://github.com/hamdanal/rich-argparse/assets/93259987/ae4a4968-1008-4fcd-8131-7a90292a7f3f)\n\n[![tests](https://github.com/hamdanal/rich-argparse/actions/workflows/tests.yml/badge.svg)\n](https://github.com/hamdanal/rich-argparse/actions/workflows/tests.yml)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/hamdanal/rich-argparse/main.svg)\n](https://results.pre-commit.ci/latest/github/hamdanal/rich-argparse/main)\n[![Downloads](https://img.shields.io/pypi/dm/rich-argparse)](https://pypistats.org/packages/rich-argparse)\n[![Python Version](https://img.shields.io/pypi/pyversions/rich-argparse)\n![Release](https://img.shields.io/pypi/v/rich-argparse)\n](https://pypi.org/project/rich-argparse/)\n\nFormat argparse and optparse help using [rich](https://pypi.org/project/rich).\n\n*rich-argparse* improves the look and readability of argparse's help while requiring minimal\nchanges to the code.\n\n## Table of contents\n\n* [Installation](#installation)\n* [Usage](#usage)\n* [Output styles](#output-styles)\n  * [Colors](#customize-the-colors)\n  * [Group names](#customize-the-group-name-format)\n  * [Highlighting patterns](#special-text-highlighting)\n  * [\"usage\"](#colors-in-the-usage)\n  * [--version](#colors-in---version)\n  * [Rich renderables](#rich-descriptions-and-epilog)\n* [Subparsers](#working-with-subparsers)\n* [Documenting your CLI](#generate-help-preview)\n* [Third party formatters](#working-with-third-party-formatters) (ft. django)\n* [Optparse](#optparse-support) (experimental)\n* [Legacy Windows](#legacy-windows-support)\n\n## Installation\n\nInstall from PyPI with pip or your favorite tool.\n\n```sh\npip install rich-argparse\n```\n\n## Usage\n\nSimply pass `formatter_class` to the argument parser\n```python\nimport argparse\nfrom rich_argparse import RichHelpFormatter\n\nparser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)\n...\n```\n\n*rich-argparse* defines equivalents to argparse's [built-in formatters](\nhttps://docs.python.org/3/library/argparse.html#formatter-class):\n\n| `rich_argparse` formatter | equivalent in `argparse` |\n|---------------------------|--------------------------|\n| `RichHelpFormatter` | `HelpFormatter` |\n| `RawDescriptionRichHelpFormatter` | `RawDescriptionHelpFormatter` |\n| `RawTextRichHelpFormatter` | `RawTextHelpFormatter` |\n| `ArgumentDefaultsRichHelpFormatter` | `ArgumentDefaultsHelpFormatter` |\n| `MetavarTypeRichHelpFormatter` | `MetavarTypeHelpFormatter` |\n\n## Output styles\n\nThe default styles used by *rich-argparse* are carefully chosen to work in different light and dark\nthemes.\n\n### Customize the colors\n\nYou can customize the colors in the output by modifying the `styles` dictionary on the formatter\nclass. *rich-argparse* defines the following styles:\n\n```python\n{\n    'argparse.args': 'cyan',  # for positional-arguments and --options (e.g \"--help\")\n    'argparse.groups': 'dark_orange',  # for group names (e.g. \"positional arguments\")\n    'argparse.help': 'default',  # for argument's help text (e.g. \"show this help message and exit\")\n    'argparse.metavar': 'dark_cyan',  # for metavariables (e.g. \"FILE\" in \"--file FILE\")\n    'argparse.prog': 'grey50',  # for %(prog)s in the usage (e.g. \"foo\" in \"Usage: foo [options]\")\n    'argparse.syntax': 'bold',  # for highlights of back-tick quoted text (e.g. \"`some text`\")\n    'argparse.text': 'default',  # for descriptions, epilog, and --version (e.g. \"A program to foo\")\n    'argparse.default': 'italic',  # for %(default)s in the help (e.g. \"Value\" in \"(default: Value)\")\n}\n```\n\nFor example, to make the description and epilog *italic*, change the `argparse.text` style:\n\n```python\nRichHelpFormatter.styles[\"argparse.text\"] = \"italic\"\n```\n\n### Customize the group name format\n\nYou can change how the names of the groups (like `'positional arguments'` and `'options'`) are\nformatted by setting the `RichHelpFormatter.group_name_formatter` which is set to `str.title` by\ndefault. Any callable that takes the group name as an input and returns a str works:\n\n```python\nRichHelpFormatter.group_name_formatter = str.upper  # Make group names UPPERCASE\n```\n\n### Special text highlighting\n\nYou can [highlight patterns](https://rich.readthedocs.io/en/stable/highlighting.html) in the\narguments help and the description and epilog using regular expressions. By default,\n*rich-argparse* highlights patterns of `--options-with-hyphens` using the `argparse.args` style\nand patterns of `` `back tick quoted text` `` using the `argparse.syntax` style. You can control\nwhat patterns are highlighted by modifying the `RichHelpFormatter.highlights` list. To disable all\nhighlights, you can clear this list using `RichHelpFormatter.highlights.clear()`.\n\nYou can also add custom highlight patterns and styles. The following example highlights all\noccurrences of `pyproject.toml` in green:\n\n```python\n# Add a style called `pyproject` which applies a green style (any rich style works)\nRichHelpFormatter.styles[\"argparse.pyproject\"] = \"green\"\n# Add the highlight regex (the regex group name must match an existing style name)\nRichHelpFormatter.highlights.append(r\"\\b(?P<pyproject>pyproject\\.toml)\\b\")\n# Pass the formatter class to argparse\nparser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)\n...\n```\n\n### Colors in the `usage`\n\nThe usage **generated by the formatter** is colored using the `argparse.args` and `argparse.metavar`\nstyles. If you use a custom `usage` message in the parser, it will treated as \"plain text\" and will\n**not** be colored by default. You can enable colors in user defined usage message through\n[console markup](https://rich.readthedocs.io/en/stable/markup.html) by setting\n`RichHelpFormatter.usage_markup = True`. If you enable this option, make sure to [escape](\nhttps://rich.readthedocs.io/en/stable/markup.html#escaping) any square brackets in the usage text.\n\n### Colors in `--version`\n\nIf you use the `\"version\"` action from argparse, you can use console markup in the `version` string:\n\n```python\nparser.add_argument(\n    \"--version\", action=\"version\", version=\"[argparse.prog]%(prog)s[/] version [i]1.0.0[/]\"\n)\n```\n\nNote that the `argparse.text` style is applied to the `version` string similar to the description\nand epilog.\n\n### Rich descriptions and epilog\n\nYou can use any rich renderable in the descriptions and epilog. This includes all built-in rich\nrenderables like `Table` and `Markdown` and any custom renderables defined using the\n[Console Protcol](https://rich.readthedocs.io/en/stable/protocol.html#console-protocol).\n\n```python\nimport argparse\nfrom rich.markdown import Markdown\nfrom rich_argparse import RichHelpFormatter\n\ndescription = \"\"\"\n# My program\n\nThis is a markdown description of my program.\n\n* It has a list\n* And a table\n\n| Column 1 | Column 2 |\n| -------- | -------- |\n| Value 1  | Value 2  |\n\"\"\"\nparser = argparse.ArgumentParser(\n    description=Markdown(description, style=\"argparse.text\"),\n    formatter_class=RichHelpFormatter,\n)\n...\n```\nCertain features are **disabled** for arbitrary renderables other than strings, including:\n\n* Syntax highlighting with `RichHelpFormatter.highlights`\n* Styling with the `\"argparse.text\"` style defined in `RichHelpFormatter.styles`\n* Replacement of `%(prog)s` with the program name\n\nArbitrary renderables are displayed \"as is\" except for long runs of empty lines that get truncated\nto two empty lines following the behavior of argparse.\n\n## Working with subparsers\n\nSubparsers do not inherit the formatter class from the parent parser by default. You have to pass\nthe formatter class explicitly:\n\n```python\nsubparsers = parser.add_subparsers(...)\np1 = subparsers.add_parser(..., formatter_class=parser.formatter_class)\np2 = subparsers.add_parser(..., formatter_class=parser.formatter_class)\n```\n\n## Generate help preview\n\nYou can generate a preview of the help message for your CLI in SVG, HTML, or TXT formats using the\n`HelpPreviewAction` action. This is useful for including the help message in the documentation of\nyour app. The action uses the\n[rich exporting API](https://rich.readthedocs.io/en/stable/console.html#exporting) internally.\n\n```python\nimport argparse\nfrom rich.terminal_theme import DIMMED_MONOKAI\nfrom rich_argparse import HelpPreviewAction, RichHelpFormatter\n\nparser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)\n...\nparser.add_argument(\n    \"--generate-help-preview\",\n    action=HelpPreviewAction,\n    path=\"help-preview.svg\",  # (optional) or \"help-preview.html\" or \"help-preview.txt\"\n    export_kwds={\"theme\": DIMMED_MONOKAI},  # (optional) keywords passed to console.save_... methods\n)\n```\nThis action is hidden, it won't show up in the help message or in the parsed arguments namespace.\n\nUse it like this:\n\n```sh\npython my_cli.py --generate-help-preview  # generates help-preview.svg (default path specified above)\n# or\npython my_cli.py --generate-help-preview my-help.svg  # generates my-help.svg\n# or\nCOLUMNS=120 python my_cli.py --generate-help-preview  # force the width of the output to 120 columns\n```\n\n## Working with third party formatters\n\n*rich-argparse* can be used with other formatters that **do not rely on the private internals**\nof `argparse.HelpFormatter`. A popular example is [django](https://pypi.org/project/django) that\ndefines a custom help formatter that is used with its built in commands as well as with extension\nlibraries and user defined commands. To use *rich-argparse* in your django project, change your\n`manage.py` file as follows:\n\n```diff\ndiff --git a/my_project/manage.py b/my_project/manage.py\nindex 7fb6855..5e5d48a 100755\n--- a/my_project/manage.py\n+++ b/my_project/manage.py\n@@ -1,22 +1,38 @@\n #!/usr/bin/env python\n \"\"\"Django's command-line utility for administrative tasks.\"\"\"\n import os\n import sys\n\n\n def main():\n     \"\"\"Run administrative tasks.\"\"\"\n     os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_project.settings')\n     try:\n         from django.core.management import execute_from_command_line\n     except ImportError as exc:\n         raise ImportError(\n             \"Couldn't import Django. Are you sure it's installed and \"\n             \"available on your PYTHONPATH environment variable? Did you \"\n             \"forget to activate a virtual environment?\"\n         ) from exc\n+\n+    from django.core.management.base import BaseCommand, DjangoHelpFormatter\n+    from rich_argparse import RichHelpFormatter\n+\n+    class DjangoRichHelpFormatter(DjangoHelpFormatter, RichHelpFormatter):  # django first\n+        \"\"\"A rich-based help formatter for django commands.\"\"\"\n+\n+    original_create_parser = BaseCommand.create_parser\n+\n+    def create_parser(*args, **kwargs):\n+        parser = original_create_parser(*args, **kwargs)\n+        parser.formatter_class = DjangoRichHelpFormatter  # set the formatter_class\n+        return parser\n+\n+    BaseCommand.create_parser = create_parser\n+\n     execute_from_command_line(sys.argv)\n\n\n if __name__ == '__main__':\n     main()\n```\n\nNow try out some command like `python manage.py runserver --help` and notice how the special\nordering of the arguments applied by django is respected by the new help formatter.\n\n## Optparse support\n\n*rich-argparse* now ships with experimental support for [optparse](\nhttps://docs.python.org/3/library/optparse.html).\n\nImport optparse help formatters from `rich_argparse.optparse`:\n\n```python\nimport optparse\nfrom rich_argparse.optparse import IndentedRichHelpFormatter  # or TitledRichHelpFormatter\n\nparser = optparse.OptionParser(formatter=IndentedRichHelpFormatter())\n...\n```\n\nYou can also generated a more helpful usage message by passing `usage=GENERATE_USAGE` to the\nparser. This is similar to the default behavior of `argparse`.\n\n```python\nfrom rich_argparse.optparse import GENERATE_USAGE, IndentedRichHelpFormatter\n\nparser = optparse.OptionParser(usage=GENERATE_USAGE, formatter=IndentedRichHelpFormatter())\n```\n\nSimilar to `argparse`, you can customize the styles used by the formatter by modifying the\n`RichHelpFormatter.styles` dictionary. These are the same styles used by `argparse` but with\nthe `optparse.` prefix instead:\n\n```python\nRichHelpFormatter.styles[\"optparse.metavar\"] = \"bold magenta\"\n```\n\nSyntax highlighting works the same as with `argparse`.\n\nColors in the `usage` are only supported when using `GENERATE_USAGE`.\n\nCustomizing the group name format is not supported. optparse uses Title Case format by default.\n\n## Legacy Windows support\n\nIf your application still runs on legacy Windows versions (older than Windows 10), you'll need to\nenable ANSI escape sequences by calling `colorama.init()` otherwise colors will be disabled:\n\n```python\nimport argparse\nimport colorama\nfrom rich_argparse import RichHelpFormatter\n\ncolorama.init()\nparser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)\n...\n```\nThis is **not** required on Windows 10 and newer or on other operating systems.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Rich help formatters for argparse and optparse",
    "version": "1.4.0",
    "project_urls": {
        "Changelog": "https://github.com/hamdanal/rich-argparse/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/hamdanal/rich-argparse#rich-argparse",
        "Homepage": "https://github.com/hamdanal/rich-argparse",
        "Issue-Tracker": "https://github.com/hamdanal/rich-argparse/issues"
    },
    "split_keywords": [
        "argparse",
        "help-formatter",
        "optparse",
        "rich"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2f619c1208dd565f13ff6062db31006b6ddf4c68c1946d5ee7bc0fec0592f1d",
                "md5": "6ca61917037fec570b616cb2356004e9",
                "sha256": "68b263d3628d07b1d27cfe6ad896da2f5a5583ee2ba226aeeb24459840023b38"
            },
            "downloads": -1,
            "filename": "rich_argparse-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6ca61917037fec570b616cb2356004e9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 19948,
            "upload_time": "2023-10-21T17:30:12",
            "upload_time_iso_8601": "2023-10-21T17:30:12.970583Z",
            "url": "https://files.pythonhosted.org/packages/c2/f6/19c1208dd565f13ff6062db31006b6ddf4c68c1946d5ee7bc0fec0592f1d/rich_argparse-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7b044b0b9b06662a4559041a88c2d31e93ecbc8aca1c45fee10a0c1a000b7274",
                "md5": "91e4a56b276b64796cad83968bcfd77e",
                "sha256": "c275f34ea3afe36aec6342c2a2298893104b5650528941fb53c21067276dba19"
            },
            "downloads": -1,
            "filename": "rich_argparse-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "91e4a56b276b64796cad83968bcfd77e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 17112,
            "upload_time": "2023-10-21T17:30:14",
            "upload_time_iso_8601": "2023-10-21T17:30:14.757590Z",
            "url": "https://files.pythonhosted.org/packages/7b/04/4b0b9b06662a4559041a88c2d31e93ecbc8aca1c45fee10a0c1a000b7274/rich_argparse-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-21 17:30:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hamdanal",
    "github_project": "rich-argparse",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "rich-argparse"
}
        
Elapsed time: 0.15100s