clize: Turn functions into command-line interfaces¶
Clize is an argument parser for Python. It focuses on minimizing the effort required to create them:
- Command-line interfaces are created by passing functions to
clize.run
. - Parameter types are deduced from the functions’ parameters.
- A
--help
message is generated from your docstrings. Seriously, why does this still need to be a bullet point? - Decorators can be used to reuse functionality across functions.
- Clize can be extended with new parameter behavior.
Here’s an example:
from sigtools.modifiers import kwoargs
from clize import run
@kwoargs('no_capitalize') # turns no_capitalize into a keyword-only parameter
# on Python 2
def hello_world(name=None, no_capitalize=False):
"""Greets the world or the given name.
name: If specified, only greet this person.
no_capitalize: Don't capitalize the given name.
"""
if name:
if not no_capitalize:
name = name.title()
return 'Hello {0}!'.format(name)
return 'Hello world!'
if __name__ == '__main__':
run(hello_world)
run
takes the function and automatically produces a command-line
interface for it:
$ pip install --user clize
$ python examples/hello.py --help
Usage: examples/hello.py [OPTIONS] [name]
Greets the world or the given name.
Positional arguments:
name If specified, only greet this person.
Options:
--no-capitalize Don't capitalize the give name.
Other actions:
-h, --help Show the help
$ python hello.py
Hello world!
$ python hello.py john
Hello John!
$ python hello.py dave --no-capitalize
Hello dave!
Interested?
- Follow the tutorial
- Browse the examples
- Ask for help on Gitter
- Check out why Clize was made
- Star, watch or fork Clize on GitHub
Here is the full table of contents:
Getting started¶
This section contains tutorials for the most commonly used features of Clize.
Guides¶
These documents document specific aspects or usages of Clize.
Reference¶
The user reference lists all capabilities of each kind of parameter. The API reference comes in handy if you’re extending clize.
- User reference
- Annotations for parameters that handle a value
- Positional parameters
- Parameter that collects remaining positional arguments
- Named parameters
- Named parameters that take an argument
- Named parameters that take an integer argument
- Flag parameters
- Mapped parameters
- Repeatable parameters
- Decorated arguments
- Annotations that work on any parameter
- Customizing the help using the docstring
- API Reference
Project documentation¶
Information on how Clize is organized as a project.