Skip to main content

click-compose

Build Status PyPI

Composable Click callback utilities for building flexible CLI applications.

Installation

$ pip install click-compose

Or with uv:

$ uv add click-compose

Quick Start

click-compose provides utilities for composing Click callbacks:

multi_callback

Combine multiple callbacks into a single callback that applies them in sequence. Use a tuple for type-checked, type-changing chains of up to ten callbacks:

"""Example of using multi_callback to combine validators."""

import click

from click_compose import multi_callback


def validate_positive(
    _ctx: click.Context | None,
    _param: click.Parameter | None,
    value: int,
) -> int:
    """Validate that value is positive."""
    if value <= 0:
        msg = "Must be positive"
        raise click.BadParameter(message=msg)
    return value


MAX_VALUE = 100


def validate_max_100(
    _ctx: click.Context | None,
    _param: click.Parameter | None,
    value: int,
) -> int:
    """Validate that value is at most 100."""
    if value > MAX_VALUE:
        msg = "Must be <= 100"
        raise click.BadParameter(message=msg)
    return value


@click.command()
@click.option(
    "--count",
    type=int,
    callback=multi_callback(
        callbacks=(validate_positive, validate_max_100),
    ),
)
def cmd(count: int) -> None:
    """Example command with multiple validators."""
    click.echo(message=f"Count: {count}")

sequence_validator

Apply a validator to each element in a sequence (useful with multiple=True):

"""Example of using sequence_validator with multiple values."""

import click

from click_compose import sequence_validator


def validate_positive(
    _ctx: click.Context | None,
    _param: click.Parameter | None,
    value: int,
) -> int:
    """Validate that value is positive."""
    if value <= 0:
        msg = "Must be positive"
        raise click.BadParameter(message=msg)
    return value


@click.command()
@click.option(
    "--numbers",
    multiple=True,
    type=int,
    callback=sequence_validator(validator=validate_positive),
)
def cmd(numbers: tuple[int, ...]) -> None:
    """Example command with sequence validation."""
    click.echo(message=f"Sum: {sum(numbers)}")

deduplicate

Remove duplicates from a sequence while preserving order (useful with multiple=True):

"""Example of using ``deduplicate`` to remove duplicate values."""

import click

from click_compose import deduplicate


@click.command()
@click.option(
    "--tags",
    multiple=True,
    type=str,
    callback=deduplicate,
)
def cmd(tags: tuple[str, ...]) -> None:
    """Example command that removes duplicate tags."""
    click.echo(message=f"Unique tags: {', '.join(tags)}")

Documentation

See the full documentation.

Metadata

Release files for click-compose 2026.9.16.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for click-compose 2026.9.16.1
File Size Uploaded
click_compose-2026.9.16.1.tar.gz 24.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for click-compose 2026.9.16.1
File Interpreter ABI Platform
click_compose-2026.9.16.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.6 kB

Release files / click_compose-2026.9.16.1.tar.gz

Download URL click_compose-2026.9.16.1.tar.gz
Size 24.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b1416164b558f4e3fbf40b3684c64559bbad708b69303910f4f605d0efc08e45
BLAKE2b-256 checksum
How to use checksums
4bd2e20f646d494df34e6c8fe5f13480910158cea85d414322f6823c4d9c8cce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / click_compose-2026.9.16.1-py3-none-any.whl

Download URL click_compose-2026.9.16.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
259fe12e96702d70287db2b3c99346c6c9232ff5cad17f73c08f659603d4baa2
BLAKE2b-256 checksum
How to use checksums
13398141061e7aea59126c36444544fab7dd89eb3df00bb3764108e32207ecac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page