Mando: Create Python CLI apps

0.8.2 · active · verified Thu Apr 09

mando is a lightweight Python library that wraps `argparse` to simplify the creation of command-line interface (CLI) applications. It allows developers to define CLI commands using Python functions and decorators, automatically generating argument parsers from function signatures and docstrings. Key features include support for Python 3-style type annotations for argument conversion, and compatibility with various docstring formats (Sphinx, Google, NumPy). It also supports shell autocompletion through the optional `argcomplete` package. The current version, 0.8.2, was released on October 20, 2024, and focuses on Python 3 compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a command-line function using the `@command` decorator and make it executable with `main()`. It handles arguments and optional flags, showcasing how `mando` parses them from function signatures and docstrings. To run, save as `my_cli.py` and execute `python my_cli.py echo "hello world" --capitalize` or `python my_cli.py echo "hello world"`.

from mando import command, main

@command
def echo(text, capitalize=False):
    '''Echo the given text.
    :param text: The text to echo.
    :param capitalize: Whether to capitalize the text.
    '''
    if capitalize:
        text = text.upper()
    print(text)

if __name__ == '__main__':
    main()

view raw JSON →