Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Turn functions into command-line interfaces

Project description

Documentation Status Documentation Status Join the chat at https://gitter.im/epsy/clize https://travis-ci.org/epsy/clize.svg?branch=master https://coveralls.io/repos/epsy/clize/badge.svg?branch=master

Clize is an argument parser for Python. You can use Clize as an alternative to argparse if you want an even easier way to create command-line interfaces.

With Clize, you can:

  • Create command-line interfaces by creating functions and passing them to clize.run.
  • Enjoy a CLI automatically created from your functions’ parameters.
  • Bring your users familiar --help messages generated from your docstrings.
  • Reuse functionality across multiple commands using decorators.
  • Extend Clize with new parameter behavior.

Here’s an example:

from clize import run

def hello_world(name=None, *, no_capitalize=False):
    """Greets the world or the given name.

    :param name: If specified, only greet this person.
    :param 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)

Python 2.7 is supported through decorators.

The python code above can now be used on the command-line as follows:

$ pip install clize
$ python3 hello.py --help
    Usage: 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 given name.

    Other actions:
      -h, --help   Show the help
$ python3 hello.py
Hello world!
$ python3 hello.py john
Hello John!
$ python3 hello.py dave --no-capitalize
Hello dave!

You can find the documentation and tutorials at http://clize.readthedocs.io/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for clize, version 4.1.1
Filename, size File type Python version Upload date Hashes
Filename, size clize-4.1.1-py2.py3-none-any.whl (71.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size clize-4.1.1.tar.gz (65.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page