Command-line interface creation for lazy people using type hints.

commandline-interface, python, typing
pip install clizy==2.0.0a4


Clizy - command-line interface for lazy people

master branch is version 2 - currently alpha!

master contains an unstable version - a complete overhaul of the library with new features and customizations. See v1 for the current, stable version.

Why clizy?

Clizy simplifies command line interface creation by using mainly features available in Python 3.5 and higher - type hints and keyword only arguments.

No unnecessary clutter, complexity and overwhelming documentation. Keep it simple, stupid. Ideal for lazy developers.

Let's take a look at this example:

from clizy import run

class Installer:
    def __init__(self, *, index_url='https://default/'):
        self._index_url = index_url

    def install(self, packages: list):
        print(f"Install '{name}' from '{self._index_url}'")

    def search(self, pattern):
        print(f"Searching for '{pattern}' in '{self._index_url}'")

if __name__ == '__main__':

Before any explanation, let's take a look on how a very similar command-line interface is created using click:

import click
@click.option('--index-url', default='')
def cli(ctx, index_url):
    ctx.obj['index_url'] = index_url

@click.argument('packages', nargs=-1)
def install(ctx, packages):
    print(f"Install '{name}' from '{ctx.obj['index_url']}'")

def search(ctx, pattern):
    print(f"Searching for '{name}' in '{ctx.obj['index_url']}'")

if __name__ == '__main__':

Quite a difference in verbosity and readability, isn't it?

Now for a very short explanation - clizy processes the class, its methods and their arguments into this command line interface: --index-url https://custom/ install flask requests
               ^                         ^       ^     ^
               |                         |       two positional arguments
               |                         command based on a method
               keyword only becomes an optional argument

Such command line invocation using clizy will basically translates into a predictable function call like this:

Installer(index_url='https://custom/').install(['flask', 'requests'])

Interested? See the docs.