Skip to main content

Declic (DEcorator-oriented CLI Creator) is a tiny Python 3 package for creating command line interfaces

Project description

Declic (DEcorator-oriented CLI Creator) is a tiny Python 3 package for creating command line interfaces using decorators. It was inspired by the click package and is based on argparse.


>From PyPI:

pip install declic

or from Github:

pip install git+


Here is an example of Declic usage:

from declic import group, argument, command

# on_before callbacks are executed if:
# - the group itself is called
# - if any of the child of the group is called
def before_bar():
    print('before bar')

def before_sub(tata):
    print('before sub: %s' % tata)

# define the root command (a group)
@group(description='my description', on_before=before_bar)
@argument('--version', action='version', version='<the version>')
@argument('--foo', type=int, default=1)
def bar():

# define a sub-group, on_before=before_sub)
@argument('--toto', type=int, default=2)
@argument('--tata', type=str, default='aaa')
def sub(toto, tata):
    print('toto: %s' % toto)
    print('tata: %s' % tata)

# define a sub-command of the sub-group
# chain option allows to execute each parent group (if they are invokable) before the command call
# each on_before functions will be executed anyway
def mop(toto, **kwargs):
    print('kwargs: %s' % kwargs)
    print('toto: %s' % toto)

# define a sub-command of the root group
@argument('-x', type=int, default=1)
@argument('y', type=float)
def foo(x, y):
    print(x, y)

if __name__ == '__main__':
    import sys

    # or bar()

Running the cli:

$ python --help

usage: bar [-h] [--foo FOO] [--version] {sub_group,foo} ...

my description

positional arguments:

optional arguments:
  -h, --help       show this help message and exit
  --foo FOO
  --version        show program's version number and exit

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 declic, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size declic-1.0.2-py3-none-any.whl (6.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size declic-1.0.2.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page