Clize

5.0.2 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.

from clize import run

def hello(name: str = 'world', *, capitalize: bool = False):
    """Greets the world or a specific person.

    :param name: The name to greet.
    :param capitalize: Whether to capitalize the name.
    """
    if capitalize:
        name = name.title()
    print(f"Hello, {name}!")


if __name__ == '__main__':
    run(hello)

view raw JSON →