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.1.1.tar.gz (14.8 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.1.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clicommands-0.1.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for clicommands-0.1.1.tar.gz
Algorithm Hash digest
SHA256 264733ca343258e10f361d0a44889eb25d4fbcc666d86209886f688f04d6c3d4
MD5 2d9dc582f40d80698e0640df4a247e7f
BLAKE2b-256 42f6c0c4e4b4575eab4a7419abbc7a9a9c47e585c60730dfbe91c205f41ede83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clicommands-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for clicommands-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d90692dcb23138cd393e9315fba4dbd39e3ac8db604f291b4c16ebbb7430e5b3
MD5 c444e43dac1d3771f3c1cbddb0a109c7
BLAKE2b-256 fd81a288e533bae8d44803356c468eaf7663c28517926f03093a0120ae42746e

See more details on using hashes here.

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