Composable Click Utilities

2025.10.27.3 · active · verified Thu Apr 16

Click-compose is a Python library that provides composable utilities for enhancing Click callback functions, enabling the construction of flexible and modular command-line interface (CLI) applications. It extends the core functionality of the Click framework by offering tools to easily chain and combine command logic. The library is actively maintained, with its current version being 2025.10.27.3, and follows a frequent release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Click CLI application using `click-compose` to create a `callback_group` and a `composed_option`. The `cli` command acts as a group, and `shout` is a subcommand that uses a composed option to conditionally output an uppercase greeting. This illustrates how to extend Click's decorator-based approach with additional composition logic.

import click
from click_compose import callback_group, composed_option

@callback_group()
@click.command()
@click.option('--name', default='World', help='The name to greet.')
def cli(name):
    """A simple CLI greeting utility."""
    click.echo(f'Hello, {name}!')

@cli.command()
@composed_option('--caps', is_flag=True, help='Say hello in uppercase.')
def shout(caps, name):
    """Greets in an excited manner."""
    message = f'HEY {name.upper()}!' if caps else f'Hey {name}!'
    click.echo(message)

if __name__ == '__main__':
    cli()

view raw JSON →