Clize is a Python library that simplifies the creation of command-line interfaces (CLIs) by directly transforming Python functions into CLIs. It automatically infers CLI parameters from function signatures and generates comprehensive `--help` messages from docstrings. The library is actively maintained, with the current stable version being 5.0.2.
pip install clizeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a simple CLI using `clize.run`. It defines a function `hello` with a positional argument `name` and a keyword-only argument `capitalize`. Running this script from the command line will automatically generate a CLI, including a `--help` message from the docstring.
Review usage of `bytes` annotations in function parameters and adjust expectations or encoding/decoding logic if necessary.
Replace `convert_default` with `clize.Parameter.cli_default` for specifying default values that are converted by CLI value converters.
Set mutable default arguments to `None` and initialize the mutable object inside the function if `None` is detected (e.g., `if my_list is None: my_list = []`).
Upgrade to `clize` version 5.0.1 or newer if you are using `alt=` with a dictionary to define alternate commands.
Install clize using pip: `pip install clize`
Provide the missing positional argument when running the command, e.g., `python your_script.py 'hello'`.
Ensure all command-line arguments correspond to the function's expected positional parameters, or define a parameter to collect extra arguments (e.g., `*args`).
Provide an argument that can be correctly converted by the parameter's type, or explicitly define a converter for the parameter using type annotations, such as `param:int` or `param:converter_function`.
Upgrade pip and reinstall Clize: `pip install --upgrade pip` followed by `pip install clize --upgrade` to ensure all dependencies are installed.