Skip to main content

A collection of decorators to build command-line tools with minimal effort

Project description



A collection of decorators wrapping argparse module for building command-line tools with minimal effort.

Quick start


$ pip install argtools

Building a simple command-line tool

# examples/
from argtools import command, argument

@argument('foo', help='a positional arugment')
@argument('--bar', default=3, help='an optional argument')
def main(args):
    """ One line description here

    Write details here (printed with --help|-h)
    return 1  # return code

if __name__ == '__main__':
$ python
$ python -v   # Increasing the verbosity of logging module

The argument decorator has the same api as argparse.ArgumentParser.add_argument. See for details.

Building subcommands

# examples/
from argtools import command, argument

def foo(args):
    """ This is foo
    print 'foo'

def bar(args):
    """ This is bar
    print 'bar'

@command.add_sub(name=baz)  # set different name
def bar(args):
    """ This is baz
    print 'baz'

if __name__ == '__main__':
$ python foo      # print foo
$ python bar      # print bar
$ python bar -h   # print help text of bar subcommand

Other features

  • In, the logging module is setup. You can control the verbosity with options: -v, -vv, ..
  • In, SIGPIPE occured inside of wrapped function will be ignored to ease piping.
  • To use group or exclusive functionality of argparse, give argument objects (e.g. arg1, arg2, arg3) as, arg2, arg3) or @argument.exclusive(arg1, arg2, arg3), respectively (documentation is #TODO).
  • Builtin options: -v, --verbose and --debug can be turned off by setting command.add_verbose = False or command.add_debug = False

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

argtools-0.1.6.tar.gz (4.8 kB view hashes)

Uploaded source

Supported by

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