Skip to main content
Tests Test Coverage Latest release BSD-3 clause license PyPI - Python Version

cltoolbox: Easy Command Line Interfaces

cltoolbox is a wrapper around argparse, and allows you to write complete CLI applications in seconds using a simple decorator.

Significant portions of this code are based on mando. The primary differences between mando and cltoolbox are:

  • cltoolbox supports automatic detection of Sphinx, Google, and Numpy docstring formats by using the docstring_parser library

  • cltoolbox supports python 3.10+

If you need support of the mando formatted docstring or python 2 you have to use mando instead of cltoolbox.

Installation

pip

pip install cltoolbox

conda

conda install -c conda-forge cltoolbox

The problem

The argparse module that comes with Python requires a programmer to duplicate information that Python can easily parse from the function signature and docstring. The cltoolbox does this for you by using decorators.

Quickstart

from cltoolbox import command, main


@command
def echo(text, capitalize=False):
    """Echo the given text."""
    if capitalize:
        text = text.upper()
    print(text)


if __name__ == "__main__":
    main()

Generated help:

$ python example.py -h
usage: example.py [-h] {echo} ...

positional arguments:
  {echo}
    echo      Echo the given text.

optional arguments:
  -h, --help  show this help message and exit

$ python example.py echo -h
usage: example.py echo [-h] [--capitalize] text

Echo the given text.

positional arguments:
  text

optional arguments:
  -h, --help    show this help message and exit
  --capitalize

Actual usage:

$ python example.py echo spam
spam
$ python example.py echo --capitalize spam
SPAM

A real example

Something more complex and real-world-ish. The code:

from cltoolbox import command, main


@command
def push(repository, all=False, dry_run=False, force=False, thin=False):
    """Update remote refs along with associated objects.

    :param repository: Repository to push to.
    :param --all: Push all refs.
    :param -n, --dry-run: Dry run.
    :param -f, --force: Force updates.
    :param --thin: Use thin pack."""

    print(
        "Pushing to {0}. All: {1}, dry run: {2}, force: {3}, thin: {4}".format(
            repository, all, dry_run, force, thin
        )
    )


if __name__ == "__main__":
    main()

cltoolbox understands Sphinx, Google, and Numpy dostrings, from which it can create short options and their help for you.

$ python git.py push -h
usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository

Update remote refs along with associated objects.

positional arguments:
  repository     Repository to push to.

optional arguments:
  -h, --help     show this help message and exit
  --all          Push all refs.
  -n, --dry-run  Dry run.
  -f, --force    Force updates.
  --thin         Use thin pack.

Let’s try it!

$ python git.py push --all myrepo
Pushing to myrepo. All: True, dry run: False, force: False, thin: False

$ python git.py push --all -f myrepo
Pushing to myrepo. All: True, dry run: False, force: True, thin: False

$ python git.py push --all -fn myrepo
Pushing to myrepo. All: True, dry run: True, force: True, thin: False

$ python git.py push --thin -fn myrepo
Pushing to myrepo. All: False, dry run: True, force: True, thin: True

$ python git.py push --thin
usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository
git.py push: error: too few arguments

Amazed uh? Yes, cltoolbox got the short options and the help from the docstring! You can put much more in the docstring, and if that isn’t enough, there’s an @arg decorator to customize the arguments that get passed to argparse.

Type annotations

cltoolbox understands Python 3-style type annotations and will warn the user if the arguments given to a command are of the wrong type.

from cltoolbox import command, main


@command
def duplicate(string, times: int):
    """Duplicate text.

    :param string: The text to duplicate.
    :param times: How many times to duplicate."""

    print(string * times)


if __name__ == "__main__":
    main()
$ python3 test.py duplicate "test " 5
test test test test test

$ python3 test.py duplicate "test " foo
usage: test.py duplicate [-h] string times
test.py duplicate: error: argument times: invalid int value: 'foo'

The cltoolbox supports shell autocompletion via the argcomplete package and supports custom format classes. For a complete documentation, visit https://timcera.bitbucket.io/cltoolbox/docs/index.html

Release files for cltoolbox 4.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cltoolbox 4.0.4
File Size Uploaded
cltoolbox-4.0.4.tar.gz 51.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cltoolbox 4.0.4
File Interpreter ABI Platform
cltoolbox-4.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 86.4 kB

Release files / cltoolbox-4.0.4.tar.gz

Download URL cltoolbox-4.0.4.tar.gz
Size 51.4 kB
Tags Source
SHA-256 checksum
How to use checksums
38b12636f0ea2fdb4109449515a92e9ec53b8a47f1a248ba545b210944bf6e4c
BLAKE2b-256 checksum
How to use checksums
427b48097b5d979dd1aa2c5ff5cab1db45e5c49d0f6a55f9bb34f0751423b445
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / cltoolbox-4.0.4-py3-none-any.whl

Download URL cltoolbox-4.0.4-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a74cc71dec7ff6e098716df23df98344845eb2ecd60903933cdba7154122207
BLAKE2b-256 checksum
How to use checksums
33774209d3d4bafa945a2cca594d4dce60b68a6585a693fd904d68373a2d97b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

4.0.4 This release

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.1

1 release file

2.0.0

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

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