Skip to main content

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.

Installation

>From PyPI:

pip install declic

or from Github:

pip install git+https://github.com/Septaris/declic.git

Usage

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():
    print('bar')

# define a sub-group
@bar.group(invokable=True, 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
@sub.command(chain=True)
def mop(toto, **kwargs):
    print('kwargs: %s' % kwargs)
    print('toto: %s' % toto)

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


if __name__ == '__main__':
    import sys

    bar(sys.argv[1:])
    # or bar()

Running the cli:

$ python my_file.py --help

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

my description

positional arguments:
  {sub,foo}

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

Release files for declic 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for declic 1.0.2
File Size Uploaded
declic-1.0.2.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for declic 1.0.2
File Interpreter ABI Platform
declic-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / declic-1.0.2.tar.gz

Download URL declic-1.0.2.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a43c07911df2f4ca74a0cb8931fa7984462de92ddcbc90126644255cfaa72613
BLAKE2b-256 checksum
How to use checksums
dac6b60e5b00681713746c672688ba621e2e753e1701dcad3e6cad376809e0b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / declic-1.0.2-py3-none-any.whl

Download URL declic-1.0.2-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98030c209f43fb97b72c83b07e8e97966fda80ba660d92967318be15244fcdac
BLAKE2b-256 checksum
How to use checksums
fb258c8f7fdeed0f64986c4903535cb62b9dab9319349641fb9a0d7f70161987
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page