Skip to main content

Lightweight CLI framework for Python projects with automatic command discovery

Project description

clicommands

Lightweight Python library for managing command-line commands with automatic discovery.

Features

  • Automatic command discovery via commands/ directory or .commands.json
  • Two ways to define commands: function suffixed with _command or Command class
  • Argument parsing API: classify_args, parse_args_from_config
  • Envfile loading: ENVFILE_PATH support for loading .env
  • Built-in commands: version, copy, varenv

Installation

pip install clicommands

Quick Start

  1. Create a cli.py in your package:
import sys
from pathlib import Path
from clicommands.helpers import cli_main

def main(argv=None):
    cli_file_path = Path(__file__)
    result = cli_main(cli_file_path, argv)
    return int(result) if isinstance(result, (int, bool)) else (0 if result else 1)

if __name__ == "__main__":
    sys.exit(main())
  1. Add a commands/ directory with your commands:
# commands/hello.py
def hello_command(args: list[str]) -> bool:
    """Say hello."""
    print("Hello, world!")
    return True
  1. Run: python -m mypackage.cli hello

.commands.json Configuration

{
  "packages": ["other_package"],
  "directories": ["commands"],
  "commands": []
}
  • packages: Packages to import commands from
  • directories: Paths to command directories
  • commands: Additional commands

Documentation

  • docs/purpose.md — Purpose and use cases
  • docs/structure.md — Project organization
  • docs/development.md — Development guidelines
  • docs/AI.md — AI assistant contract

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

clicommands-0.2.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

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

clicommands-0.2.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file clicommands-0.2.0.tar.gz.

File metadata

  • Download URL: clicommands-0.2.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clicommands-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e00b3866a69ee1b770e48f65c86342c01f9883c41c206a683af11b7af7ebe038
MD5 7417e36002eb35037608636f593eb716
BLAKE2b-256 6fe5ed8cb5b6c9e0a6a2a3fefdd25cfbce6c198410fd5b8321519b2c94ccdfcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for clicommands-0.2.0.tar.gz:

Publisher: release.yml on octolo/python-clicommands

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

File details

Details for the file clicommands-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: clicommands-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clicommands-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a37efffd79911198479b29e65395a82f87b26b962b8da3ec8eb4a139922e4cdc
MD5 ba6a8ca17e935f121f3c88450b9e0466
BLAKE2b-256 05b2abff7420d24320ac5c37db87e20293d286b3d1d071eb1c3b9d1999317f2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for clicommands-0.2.0-py3-none-any.whl:

Publisher: release.yml on octolo/python-clicommands

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