Skip to main content

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.

Source Distribution

clize-4.0.tar.gz (63.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clize-4.0-py2.py3-none-any.whl (68.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file clize-4.0.tar.gz.

File metadata

  • Download URL: clize-4.0.tar.gz
  • Upload date:
  • Size: 63.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for clize-4.0.tar.gz
Algorithm Hash digest
SHA256 635ccc281fdab71faa05c7a99535511f830d59987d1ccd66b2eed659345b7575
MD5 257f8475c5d656e7b1eddea4b1df823f
BLAKE2b-256 a153c0a9e650fd616f6731384015161ad1f8954b84cc88ee50535593fb9349ce

See more details on using hashes here.

File details

Details for the file clize-4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for clize-4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f64b7cd63ccae643c9a0dae480c03b23ca84b1d75da89e2a77296045ca7cd94c
MD5 9086ce464ebb8a815136e834ad460fa7
BLAKE2b-256 3755476356164429f1a65e8b3513cb944e3d5e30e486d3dc2be24d4c8bfb4b74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page