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.
pip install mandoVerified import paths — ran on the pinned version, not inferred.
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"`.
Upgrade to Python 3 and install `mando>=0.8.0` or pin `mando<0.8.0` for Python 2 projects (though this is not recommended).
Consult `mando` documentation on 'Other Docstring Formats' for configuration options if using non-Sphinx styles.
Decorate your command function parameters with `@arg('param_name', ...)` before the `@command` decorator to customize individual arguments.Always prefer installing `mando` via `pip install mando` to ensure you receive the latest stable version and its full feature set, especially for Python 3 development.
Install the `mando` package using pip: `pip install mando`
Ensure the script has a correct shebang (e.g., `#!/usr/bin/env python3` at the top), make it executable (`chmod +x <your_script_name>.py`), and then run it with `./<your_script_name>.py` or explicitly with `python <your_script_name>.py`.
Ensure the command-line argument matches the expected Python type annotation for that parameter. For example, if an argument is `age: int`, provide a numeric value like `--age 30` instead of `--age 'thirty'`.
Verify the exact import statement is `from mando import command, main` (and `arg` if used), and ensure there are no typos. If problems persist, consider reinstalling `mando` to ensure all components are correctly available: `pip install --upgrade mando`.