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:
"""Example of using multi_callback to combine validators."""
import click
from click_compose import multi_callback
def validate_positive(
_ctx: click.Context,
_param: click.Parameter,
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,
_param: click.Parameter,
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)}")
Documentation
See the full documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file click_compose-2025.10.27.3.tar.gz.
File metadata
- Download URL: click_compose-2025.10.27.3.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d3326a13b690ac7a0f0e99de785aa78ea81d130ba02d609e6367a7af23477a5
|
|
| MD5 |
b9d0fbbb74dd8e243f939c0000390e25
|
|
| BLAKE2b-256 |
459f7b380e5318643348e256ec31df1362b74dfa12733f76b1a97e1171ba74fe
|
Provenance
The following attestation bundles were made for click_compose-2025.10.27.3.tar.gz:
Publisher:
release.yml on adamtheturtle/click-compose
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
click_compose-2025.10.27.3.tar.gz -
Subject digest:
6d3326a13b690ac7a0f0e99de785aa78ea81d130ba02d609e6367a7af23477a5 - Sigstore transparency entry: 644825418
- Sigstore integration time:
-
Permalink:
adamtheturtle/click-compose@dfd8ee1435f96645060e34e3655f56aeb016aea1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adamtheturtle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dfd8ee1435f96645060e34e3655f56aeb016aea1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file click_compose-2025.10.27.3-py2.py3-none-any.whl.
File metadata
- Download URL: click_compose-2025.10.27.3-py2.py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6821fb769067e76d2b2e9c5d4d5e8d974002137322ab71cde65b10bf9c025834
|
|
| MD5 |
5a67dfcf2aba58b16d1804500a18c388
|
|
| BLAKE2b-256 |
453a411c2ad30f87b2e874a4a4d1578dc9fe11a6ea8f139b4e1f7ff291a934ca
|
Provenance
The following attestation bundles were made for click_compose-2025.10.27.3-py2.py3-none-any.whl:
Publisher:
release.yml on adamtheturtle/click-compose
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
click_compose-2025.10.27.3-py2.py3-none-any.whl -
Subject digest:
6821fb769067e76d2b2e9c5d4d5e8d974002137322ab71cde65b10bf9c025834 - Sigstore transparency entry: 644825437
- Sigstore integration time:
-
Permalink:
adamtheturtle/click-compose@dfd8ee1435f96645060e34e3655f56aeb016aea1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adamtheturtle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dfd8ee1435f96645060e34e3655f56aeb016aea1 -
Trigger Event:
workflow_dispatch
-
Statement type: