Typer compatibility

Typer builds command-line interfaces from function type hints, on top of Click. Since click-extra also builds on Click, it is natural to expect the two to combine: a Typer app that picks up click-extra’s configuration loading, logging and themed help. They do not combine, and this page explains why, and what to reach for instead.

Why click-extra and Typer don’t compose

click-extra extends the Click and Cloup classes installed in your environment: its commands, options and context all derive from them. Recent Typer bundles its own private copy of Click instead of using the one click-extra extends. A Typer command therefore subclasses Typer’s bundled Command, a different class from the click.Command that click-extra subclasses, even though both descend from a common Click codebase.

Because the two come from separate class lineages, they cannot be merged. A hybrid such as class MyCommand(click_extra.Command, TyperCommand) is a valid class declaration, but it inherits two unrelated Command implementations at once and cannot be instantiated: Typer hands it arguments that click-extra’s Click base does not accept. Construction aside, click-extra’s options are click.Parameter objects that Typer’s bundled parser does not recognize, so they would never be parsed. No cls= argument or runtime patch bridges this: the gap is between two copies of Click, not between two ways of using one.

How this differs from rich-click

rich-click does integrate with Typer, through its patch_typer() helper, which can look like a counterexample. The difference is in what each library changes. rich-click only restyles the help output: it overrides how help is rendered and leaves Typer’s own command construction and parsing untouched, so it never crosses the Click-lineage boundary.

click-extra’s value is the opposite kind of work. Its features run during parsing: --config loads a file and feeds it into the command’s defaults, --verbosity configures logging, --color and --version resolve ahead of the rest. That requires being a working Click command inside the same parser that runs it, which is exactly what Typer’s bundled Click forecloses. Restyling output transfers to Typer; parse-time behavior does not.

Using click-extra’s features instead

If you want the options Typer lacks (configuration files, logging control, a metadata-aware --version, themed help), build the CLI with click-extra’s own decorators. @command and @group are drop-in replacements for Click’s, and they add the full set of extra options automatically:

from click_extra import command, option

@command
@option("--unit", help="Temperature scale.")
def forecast(unit):
    """Show today's forecast."""

The extra options are there without declaring them:

$ forecast --help
Usage: forecast [OPTIONS]

  Show today's forecast.

Options:
  --unit TEXT                  Temperature scale.
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --config CONFIG_PATH         Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/forecast/{*.toml,*.yaml,*.yml
                               ,*.json,*.json5,*.jsonc,*.hjson,*.ini,*.xml,pypro
                               ject.toml}]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config FILE       Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.
  --accessible                 Accessibility mode: disable colors and render
                               tables in a plain, screen-reader-friendly format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [dark|dracula|light|manpage|monokai|nord|solarized_dark]
                               Color theme used for help screens.  [default:
                               dark]
  --show-params                Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --table-format [aligned|asciidoc|colon-grid|csv|csv-excel|csv-excel-tab|csv-unix|double-grid|double-outline|fancy-grid|fancy-outline|github|grid|heavy-grid|heavy-outline|hjson|html|jira|json|json5|jsonc|latex|latex-booktabs|latex-longtable|latex-raw|mediawiki|mixed-grid|mixed-outline|moinmoin|orgtbl|outline|pipe|plain|presto|pretty|psql|rounded-grid|rounded-outline|rst|simple|simple-grid|simple-outline|textile|toml|tsv|unsafehtml|vertical|xml|yaml|youtrack]
                               Rendering style of tables.  [default: rounded-
                               outline]
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --man                        Show the command's man page (roff) and exit.
  --version                    Show the version and exit.
  -h, --help                   Show this message and exit.

See the tutorial and commands pages for the full feature set. The trade-off is the authoring style: click-extra defines parameters with explicit @option and @argument decorators rather than from function type hints. If type-hint-driven definition matters more than the extra options, stay on Typer and reach for rich-click to prettify its help.