Skip to main content

Parser for command-line applications

Project description


A simple parser for building graceful command-line interfaces, with chained commands and colorful usage messages. Clips uses getopt for parsing command arguments and options (scanning mode is GNU-flavoured).

Colors are implemented through ANSI codes and they are not expected to work on Windows. More generally, please note that Clips is not tested for Windows environment.

Quick start

Install with pip:

pip install clips

Usage example

A console with a chained command:

# init console
console = ArgParser(
    'myconsole',                # prog. name
    description=description,    # prog. description
    banner=banner               # usage banner

# add a console-level argument
console.add_argument('-v','--version',help='Show version')

# add a console command
cmd = console.add_command('command',help='A command')

# add a subcommand
subcmd = cmd.add_command('subcommand',help='A subcommand')

# add an argument to subcommand
subcmd.add_argument('arg',help='Argument for this subcommand')

Parsing method returns a dictionary of user context,

# parse arguments
args = console.parse_args(['command','subcommand','this'])

so that output is:

    '-h': False,
    '--help': False,
    '-v': False,
    '--version': False,
    'command': True,
    'subcommand': True,
    'arg': 'this'

To display usage help:

# console-level usage

# command-level usage

To disable internal management of help option:

# init console
console = ArgParser(
    'myconsole',                # prog. name
    add_help=False              # no help hook

Use colors for title and text:

# init console
console = ArgParser(
    'myconsole',                # prog. name
    title_fg='orange',          # title foreground color
    title_bg='green',           # title background color
    text_fg='green',            # text foreground color
    text_bg='orange'            # text background color

Group commands by sections (this affects only usage help):

# create section with commands
console.add_section('First section')
cmd1 = console.add_command('cmd1')
cmd2 = console.add_command('cmd2')

# another section
console.add_section('Second section')
cmd3 = console.add_command('cmd3')
cmd4 = console.add_command('cmd4')

Available colors for titles and text parts:

  • foreground: black, red, green, orange, blue, cyan, lightgrey, darkgrey, lightred, lightgreen, yellow, lightblue, pink, lightcyan
  • background: black, red, green, orange, blue, purple, cyan, lightgrey

Project details

Release history Release notifications

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
clips-1.0.0-py3-none-any.whl (6.2 kB) Copy SHA256 hash SHA256 Wheel py3
clips-1.0.0.tar.gz (5.5 kB) Copy SHA256 hash SHA256 Source None

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