Skip to main content

click-option-group

PyPI version Build status Coverage Status Supported Python versions License

click-option-group is a Click-extension package that adds option groups missing in Click.

Aim and Motivation

Click is a package for creating powerful and beautiful command line interfaces (CLI) in Python, but it has no the functionality for creating option groups.

Option groups are convenient mechanism for logical structuring CLI, also it allows you to set the specific behavior and set the relationship among grouped options (mutually exclusive options for example). Moreover, argparse stdlib package contains this functionality out of the box.

At the same time, many Click users need this functionality. You can read interesting discussions about it in the following issues:

The aim of this package is to provide group options with extensible functionality using canonical and clean API (Click-like API as far as possible).

Quickstart

Installing

Install and update using pip:

pip install -U click-option-group

A Simple Example

Here is a simple example how to use option groups in your Click-based CLI. Just use optgroup for declaring option groups by decorating your command function in Click-like API style.

# app.py

import click
from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup

@click.command()
@optgroup.group('Server configuration',
                help='The configuration of some server connection')
@optgroup.option('-h', '--host', default='localhost', help='Server host name')
@optgroup.option('-p', '--port', type=int, default=8888, help='Server port')
@optgroup.option('-n', '--attempts', type=int, default=3, help='The number of connection attempts')
@optgroup.option('-t', '--timeout', type=int, default=30, help='The server response timeout')
@optgroup.group('Input data sources', cls=RequiredMutuallyExclusiveOptionGroup,
                help='The sources of the input data')
@optgroup.option('--tsv-file', type=click.File(), help='CSV/TSV input data file')
@optgroup.option('--json-file', type=click.File(), help='JSON input data file')
@click.option('--debug/--no-debug', default=False, help='Debug flag')
def cli(**params):
    print(params)

if __name__ == '__main__':
    cli()
$ python app.py --help
Usage: app.py [OPTIONS]

Options:
  Server configuration:           The configuration of some server connection
    -h, --host TEXT               Server host name
    -p, --port INTEGER            Server port
    -n, --attempts INTEGER        The number of connection attempts
    -t, --timeout INTEGER         The server response timeout
  Input data sources: [mutually_exclusive, required]
                                  The sources of the input data
    --tsv-file FILENAME           CSV/TSV input data file
    --json-file FILENAME          JSON input data file
  --debug / --no-debug            Debug flag
  --help                          Show this message and exit.

Documentation

https://click-option-group.readthedocs.io

Metadata

Release files for asyncclick-option-group 0.5.6.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 asyncclick-option-group 0.5.6.1
File Size Uploaded Provenance Actions
asyncclick_option_group-0.5.6.1.tar.gz 22.6 kB Without provenance Details for asyncclick_option_group-0.5.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for asyncclick-option-group 0.5.6.1
File Interpreter ABI Platform Actions
asyncclick_option_group-0.5.6.1-py3-none-any.whl Python 3 none any Details for asyncclick_option_group-0.5.6.1-py3-none-any.whl

Total release size: 34.1 kB

Release files / asyncclick_option_group-0.5.6.1.tar.gz

Download URL asyncclick_option_group-0.5.6.1.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5f63d8ea4ed95f87a6060905a7a7cf8aaf2f4ac2a9173794686122f0c8a5445e
BLAKE2b-256 checksum
How to use checksums
7d2d3eb399edf0b78d39aebbc01c22a368a5399c3b2dd55db43d131e0de858d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / asyncclick_option_group-0.5.6.1-py3-none-any.whl

Download URL asyncclick_option_group-0.5.6.1-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ecc68b659189cae569a13e7ae248c509aeb1b0acef6fa093f48b8a068850f18
BLAKE2b-256 checksum
How to use checksums
cc082e943e390e6a2f35fe7ed3acbd85ae4bef48e14a6c308e2329f1b9ce4e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Security for asyncclick-option-group 0.5.6.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.6.1 This release

2 release files No provenance

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