Skip to main content

Composable Click callback utilities for building flexible CLI applications.

Project description

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 two main utilities for composing Click callbacks:

multi_callback

Combine multiple callbacks into a single callback that applies them in sequence:

import click
from click_compose import multi_callback

def validate_positive(ctx, param, value):
    if value <= 0:
        raise click.BadParameter("Must be positive")
    return value

def validate_max_100(ctx, param, value):
    if value > 100:
        raise click.BadParameter("Must be <= 100")
    return value

@click.command()
@click.option(
    "--count",
    type=int,
    callback=multi_callback([validate_positive, validate_max_100]),
)
def cmd(count):
    click.echo(f"Count: {count}")

sequence_validator

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

import click
from click_compose import sequence_validator

def validate_positive(ctx, param, value):
    if value <= 0:
        raise click.BadParameter("Must be positive")
    return value

@click.command()
@click.option(
    "--numbers",
    multiple=True,
    type=int,
    callback=sequence_validator(validate_positive),
)
def cmd(numbers):
    click.echo(f"Sum: {sum(numbers)}")

Documentation

See the full documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

click_compose-2025.10.27.1.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

click_compose-2025.10.27.1-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file click_compose-2025.10.27.1.tar.gz.

File metadata

  • Download URL: click_compose-2025.10.27.1.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for click_compose-2025.10.27.1.tar.gz
Algorithm Hash digest
SHA256 2802c8b962816f88ca0e87ff920c035193a9dbb8b27f8522911f7420c78b024b
MD5 cfbafa3ef7ec5d02110e970a04da643f
BLAKE2b-256 aade723efdf1262722590b63905b6d36d18753d64dfb9f04a2531d91bdc1ef2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for click_compose-2025.10.27.1.tar.gz:

Publisher: release.yml on adamtheturtle/click-compose

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file click_compose-2025.10.27.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for click_compose-2025.10.27.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 016035ffe6709f5719111cdae2538284f2a6d501cb3edb8ec7d99144c7dbb42e
MD5 853ed115fa3200957172fd84831fb005
BLAKE2b-256 2a026c708b6e64ab8a6bf7aa58b019167b68459b96656c3d6a72f57038c3282a

See more details on using hashes here.

Provenance

The following attestation bundles were made for click_compose-2025.10.27.1-py2.py3-none-any.whl:

Publisher: release.yml on adamtheturtle/click-compose

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page