Skip to main content

Click With Aliasing

top language code size last commit issues contributors PyPI License Downloads Monthly Downloads

A powerful extension for Click that adds command and group aliasing support with automatic async function handling and advanced parameter validation.

You can find the project on PyPi.

Features

  • Command Aliases: Create multiple names for your commands
  • Group Aliases: Add aliases to command groups
  • Help Alias (-h): Automatic -h shorthand for --help with conflict detection
  • Enhanced Options & Arguments: Mutual exclusivity, requirements, and group constraints
  • Validation Rules: Group-level validation with multiple modes (all_or_none, at_least, at_most, exactly)
  • Automatic Async Support: Seamlessly handle async functions without extra configuration
  • Drop-in Replacement: Works exactly like standard Click decorators
  • Type Safe: Full type hints support with proper IDE integration
  • Help Integration: Aliases automatically appear in help text

Installation

pip install click-with-aliasing

Requirements: Python 3.10 or newer

Documentation

  • Command - Command decorator with aliasing support
  • Group - Group decorator for organizing commands
  • Option - Enhanced options with mutual exclusivity and requirements
  • Argument - Enhanced arguments with validation constraints
  • Rule - Group-level validation rules for complex parameter logic

Note: Both -h and --help flags are supported by default. See the Command and Group documentation for details on how -h is intelligently handled when commands use it for other purposes.

Quick Start

Basic Command with Aliases

from click_with_aliasing import command

@command(name="deploy", aliases=["d", "dep"])
def deploy():
    """Deploy the application"""
    print("Deploying application...")

Now you can run any of these:

my-cli deploy
my-cli d
my-cli dep

Group with Aliases

from click_with_aliasing import group, command

@group(name="database", aliases=["db"])
def database():
    """Database management commands"""
    pass

@command(name="migrate", aliases=["m"])
def migrate():
    """Run database migrations"""
    print("Running migrations...")

database.add_command(migrate)

Usage:

my-cli database migrate  # Full names
my-cli db m              # Using aliases
my-cli database m        # Mixed usage

Enhanced Options with Validation

from click_with_aliasing import command, option

@command(name="auth")
@option("--username", requires=["password"], mutually_exclusive=["token"])
@option("--password", requires=["username"], mutually_exclusive=["token"])
@option("--token", mutually_exclusive=["username", "password"])
def auth(username, password, token):
    """Authenticate with username/password or token"""
    if token:
        print("Authenticating with token")
    elif username and password:
        print(f"Authenticating as {username}")

Usage:

my-cli auth --token abc123                          # Valid
my-cli auth --username admin --password secret      # Valid
my-cli auth --username admin                        # Error: requires password
my-cli auth --token abc123 --username admin         # Error: mutually exclusive

Validation Rules

from click_with_aliasing import command, option, rule

@command(name="deploy")
@option("--production", is_flag=True)
@option("--staging", is_flag=True)
@option("--development", is_flag=True)
@rule(["production", "staging", "development"], mode="exactly", count=1)
def deploy(production, staging, development):
    """Deploy to exactly one environment"""
    env = "production" if production else "staging" if staging else "development"
    print(f"Deploying to {env}")

Usage:

my-cli deploy --production                          # Valid
my-cli deploy --staging                             # Valid
my-cli deploy --production --staging                # Error: exactly 1 required
my-cli deploy                                       # Error: exactly 1 required

Async Support

The library automatically detects and handles async functions, meaning no extra configuration is needed.

Async Commands

import asyncio
from click_with_aliasing import command

@command(name="fetch", aliases=["f"])
async def fetch():
    """Fetch data asynchronously"""
    await asyncio.sleep(1)
    print("Data fetched!")

Async Groups

import asyncio
from click_with_aliasing import group, command

@group(name="api", aliases=["a"])
async def api_group():
    """API management commands"""
    await asyncio.sleep(0.1)  # Simulate async setup

@command(name="start", aliases=["s"])
async def start_server():
    """Start the API server"""
    print("Starting server...")

api_group.add_command(start_server)

Key Concepts

Command & Group Aliases

Add multiple names to commands and groups for convenience:

@command(name="deploy", aliases=["d", "dep"])
@group(name="database", aliases=["db", "d"])

Option Validation

Mutual Exclusivity: Only one option from a set can be used

@option("--json", mutually_exclusive=["xml", "yaml"])

Requirements: Options that must be used together

@option("--username", requires=["password"])

Group Constraints: Organize options and apply constraints collectively

@option("--json", group="format", group_mutually_exclusive=["output"])

Validation Rules

Apply group-level validation with different modes:

  • all_or_none: All parameters or none
  • at_least: Minimum number required
  • at_most: Maximum number allowed
  • exactly: Exact number required
@rule(["host", "port", "database"], mode="all_or_none")
@rule(["email", "sms", "slack"], mode="at_least", count=1)
@rule(["json", "xml", "yaml"], mode="at_most", count=1)
@rule(["file1", "file2", "file3"], mode="exactly", count=2)

Migration from Click

Migrating from standard Click is straightforward - just change your imports:

Before (Standard Click)

import click

@click.group()
def cli():
    pass

@click.command()
@click.option("--name", default="World")
@click.argument("file")
def greet(name, file):
    pass

After (Click with Aliasing)

from click_with_aliasing import group, command, option, argument

@group(aliases=["c"])
def cli():
    pass

@command(name="greet", aliases=["g"])
@option("--name", default="World", mutually_exclusive=["file"])
@argument("file", required=False, mutually_exclusive=["name"])
def greet(name, file):
    pass

All standard Click features work exactly the same, with optional enhancements available.

Help Text Integration

Aliases automatically appear in help text, and both -h and --help work for displaying help:

myapp database --help
Usage: myapp database [OPTIONS] COMMAND [ARGS]...

  Database management commands

Options:
  -h, --help  Show this message and exit.

Commands:
  migrate (m, mig)  Run database migrations
  seed (s)          Seed the database

The -h flag is automatically added unless a command uses it for another purpose (like --host), ensuring consistent help access while avoiding conflicts.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our development process, coding standards, and how to submit pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Built on top of the great Click library by the Pallets team.

Metadata

Release files for click-with-aliasing 1.2.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-with-aliasing 1.2.1
File Size Uploaded Provenance
click_with_aliasing-1.2.1.tar.gz 23.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for click-with-aliasing 1.2.1
File Interpreter ABI Platform
click_with_aliasing-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 41.0 kB

Release files / click_with_aliasing-1.2.1.tar.gz

Download URL click_with_aliasing-1.2.1.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2e07833b86da822a23e859946665541681a9c45aa67caddbb785554868296739
BLAKE2b-256 checksum
How to use checksums
d1509db5c8bc2e6df060c764b29521480e6050ec23744ccace43e43718ef0cc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / click_with_aliasing-1.2.1-py3-none-any.whl

Download URL click_with_aliasing-1.2.1-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1543b1e01723eb5ec1f2aa0328970aa2b420b224e3c8fdf98b6b7400e5a843c5
BLAKE2b-256 checksum
How to use checksums
f11f39b4d731d67d721433e58160e0bea277afe1863d7b72fc70972f5589d0a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for click-with-aliasing 1.2.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.

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