Registry / http-networking / clize
library5.0.2pypypi✓ verified 29d ago

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 clize
INSTALL
IMPORT
SIG · CLIZE
C
clize
http-networkingpythonv5.0.2
Install
2.2s avg
Import
157ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v5.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.168s · 24MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.2s · import 0.146s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

run
✓ from clize import run
The primary entry point for turning a function into a command-line interface.
Parameter
✓ from clize import Parameter
Used for advanced parameter annotations like `Parameter.cli_default`.

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)
clize --version
Debug
Known issues
breakingThe `bytes` annotation (converter) now re-encodes the corresponding parameter back to bytes, changing its behavior from previous versions.
fix
Review usage of `bytes` annotations in function parameters and adjust expectations or encoding/decoding logic if necessary.
affects: >=5.0.0
deprecatedThe `convert_default` argument to `clize.parser.value_converter` is deprecated. Its functionality should now be handled via `clize.Parameter.cli_default`.
fix
Replace `convert_default` with `clize.Parameter.cli_default` for specifying default values that are converted by CLI value converters.
affects: >=5.0.0
gotchaUsing mutable objects (e.g., lists, dictionaries) as default arguments in Python functions passed to `clize.run` can lead to unexpected shared state. Python evaluates default arguments once when the function is defined, not on each call.
fix
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 = []`).
affects: All versions
gotchaPrior to v5.0.1, using a dictionary in the `alt=` parameter of `clize.run` did not work correctly.
fix
Upgrade to `clize` version 5.0.1 or newer if you are using `alt=` with a dictionary to define alternate commands.
affects: <5.0.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'clize'
The 'clize' library has not been installed in the current Python environment.
fix
Install clize using pip: `pip install clize`
Missing required arguments: word
A positional argument defined in the decorated function was not provided on the command line.
fix
Provide the missing positional argument when running the command, e.g., `python your_script.py 'hello'`.
Received extra arguments: spam
The command line received more positional arguments than expected by the function signature.
fix
Ensure all command-line arguments correspond to the function's expected positional parameters, or define a parameter to collect extra arguments (e.g., `*args`).
TypeError: an integer is required (got type str)
Clize attempted to convert a command-line argument (which is a string) to an expected Python type, but the default type converter could not handle the string input directly.
fix
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`.
ImportError: No module named 'sigtools'
A core dependency of Clize, such as 'sigtools', was not installed correctly or is missing from the environment.
fix
Upgrade pip and reinstall Clize: `pip install --upgrade pip` followed by `pip install clize --upgrade` to ensure all dependencies are installed.
Upgrade
Version history
5.0.2latest on PyPI · released Jul 9, 2023
Audit
Dependencies
python-dateutiloptionalRequired for using `clize.converters.datetime` for date parsing.
Agent activity
25 hits · last 30 days
node
20
OpenAI (training)
1
Resources
clize — pip install clize · libregistry