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
_commandorCommandclass - Argument parsing API:
classify_args,parse_args_from_config - Envfile loading:
ENVFILE_PATHsupport for loading.env - Built-in commands:
version,copy,varenv
Installation
pip install clicommands
Quick Start
- Create a
cli.pyin 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())
- Add a
commands/directory with your commands:
# commands/hello.py
def hello_command(args: list[str]) -> bool:
"""Say hello."""
print("Hello, world!")
return True
- Run:
python -m mypackage.cli hello
.commands.json Configuration
{
"packages": ["other_package"],
"directories": ["commands"],
"commands": []
}
packages: Packages to import commands fromdirectories: Paths to command directoriescommands: Additional commands
Documentation
docs/purpose.md— Purpose and use casesdocs/structure.md— Project organizationdocs/development.md— Development guidelinesdocs/AI.md— AI assistant contract
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e00b3866a69ee1b770e48f65c86342c01f9883c41c206a683af11b7af7ebe038
|
|
| MD5 |
7417e36002eb35037608636f593eb716
|
|
| BLAKE2b-256 |
6fe5ed8cb5b6c9e0a6a2a3fefdd25cfbce6c198410fd5b8321519b2c94ccdfcd
|
Provenance
The following attestation bundles were made for clicommands-0.2.0.tar.gz:
Publisher:
release.yml on octolo/python-clicommands
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clicommands-0.2.0.tar.gz -
Subject digest:
e00b3866a69ee1b770e48f65c86342c01f9883c41c206a683af11b7af7ebe038 - Sigstore transparency entry: 1642884647
- Sigstore integration time:
-
Permalink:
octolo/python-clicommands@974db9527c5d1148079dda36e279696e77685e6c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/octolo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@974db9527c5d1148079dda36e279696e77685e6c -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a37efffd79911198479b29e65395a82f87b26b962b8da3ec8eb4a139922e4cdc
|
|
| MD5 |
ba6a8ca17e935f121f3c88450b9e0466
|
|
| BLAKE2b-256 |
05b2abff7420d24320ac5c37db87e20293d286b3d1d071eb1c3b9d1999317f2c
|
Provenance
The following attestation bundles were made for clicommands-0.2.0-py3-none-any.whl:
Publisher:
release.yml on octolo/python-clicommands
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clicommands-0.2.0-py3-none-any.whl -
Subject digest:
a37efffd79911198479b29e65395a82f87b26b962b8da3ec8eb4a139922e4cdc - Sigstore transparency entry: 1642884792
- Sigstore integration time:
-
Permalink:
octolo/python-clicommands@974db9527c5d1148079dda36e279696e77685e6c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/octolo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@974db9527c5d1148079dda36e279696e77685e6c -
Trigger Event:
push
-
Statement type: