An argparse wrapper that doesn't make you say "argh" each time you deal with it.
Python Other
Latest commit dcd3253 Aug 27, 2016 @neithere Update changelog
Failed to load latest commit information.
argh Fix #111 (support nested wraps decos) Aug 25, 2016
docs Add support for Py3.5, drop 3.2 Aug 26, 2016
test Cleanup Aug 26, 2016
.travis.yml Add support for Py3.5, drop 3.2 Aug 26, 2016
AUTHORS Fix #111 (support nested wraps decos) Aug 25, 2016
CHANGES Update changelog Aug 27, 2016
COPYING Add LGPL3 license text. This closes #101. May 11, 2016
COPYING.LESSER Add the license files. Aug 23, 2016
Makefile Added patch by Hannu Valtonen to create Debian packages. Jan 3, 2012
reqs-dev.txt Fix tests Oct 12, 2015
setup.cfg Bump version to 0.26.2 May 11, 2016 Add support for Py3.5, drop 3.2 Aug 26, 2016
tox.ini Add support for Py3.5, drop 3.2 Aug 26, 2016


Argh: The Natural CLI

Building a command-line interface? Found yourself uttering "argh!" while struggling with the API of argparse? Don't like the complexity but need the power?

Everything should be made as simple as possible, but no simpler.

—Albert Einstein (probably)

Argh is a smart wrapper for argparse. Argparse is a very powerful tool; Argh just makes it easy to use.

In a nutshell

Argh-powered applications are simple but flexible:


Declaration of commands can be decoupled from assembling and dispatching;


Commands are declared naturally, no complex API calls in most cases;


Commands are plain functions, can be used directly outside of CLI context;


The complexity of code raises with requirements;


The full power of argparse is available whenever needed;


Nested commands are a piece of cake, no messing with subparsers (though they are of course used under the hood);


Command output is processed with respect to stream encoding;


Argh can dispatch a subset of pure-argparse code, and pure-argparse code can update and dispatch a parser assembled with Argh;


The amount of boilerplate code is minimal; among other things, Argh will:

  • infer command name from function name;
  • infer arguments from function signature;
  • infer argument type from the default value;
  • infer argument action from the default value (for booleans);
  • add an alias root command help for the --help argument.
NIH free:

Argh supports completion, progress bars and everything else by being friendly to excellent 3rd-party libraries. No need to reinvent the wheel.

Sounds good? Check the tutorial!

Relation to argparse

Argh is fully compatible with argparse. You can mix Argh-agnostic and Argh-aware code. Just keep in mind that the dispatcher does some extra work that a custom dispatcher may not do.


Using pip:

$ pip install argh

Arch Linux (AUR):

$ yaourt python-argh


A very simple application with one command:

import argh

def main():
    return 'Hello world'


Run it:

$ ./
Hello world

A potentially modular application with multiple commands:

import argh

# declaring:

def echo(text):
    "Returns given word as is."
    return text

def greet(name, greeting='Hello'):
    "Greets the user with given name. The greeting is customizable."
    return greeting + ', ' + name

# assembling:

parser = argh.ArghParser()
parser.add_commands([echo, greet])

# dispatching:

if __name__ == '__main__':

Of course it works:

$ ./ greet Andy
Hello, Andy

$ ./ greet Andy -g Arrrgh
Arrrgh, Andy

Here's the auto-generated help for this application (note how the docstrings are reused):

$ ./ help

usage: {echo,greet} ...

positional arguments:
    echo        Returns given word as is.
    greet       Greets the user with given name. The greeting is customizable.

...and for a specific command (an ordinary function signature is converted to CLI arguments):

$ ./ help greet

usage: greet [-g GREETING] name

Greets the user with given name. The greeting is customizable.

positional arguments:

optional arguments:
  -g GREETING, --greeting GREETING   'Hello'

(The help messages have been simplified a bit for brevity.)

Argh easily maps plain Python functions to CLI. Sometimes this is not enough; in these cases the powerful API of argparse is also available:

@arg('text', default='hello world', nargs='+', help='The message')
def echo(text):
    print text

The approaches can be safely combined even up to this level:

# adding help to `foo` which is in the function signature:
@arg('foo', help='blah')
# these are not in the signature so they go to **kwargs:
@arg('-q', '--quux')
# the function itself:
def cmd(foo, bar=1, *args, **kwargs):
    yield foo
    yield bar
    yield ', '.join(args)
    yield kwargs['baz']
    yield kwargs['quux']



Developed by Andrey Mikhaylenko since 2010.

See file AUTHORS for a complete list of contributors to this library.


The fastest way to improve this project is to submit tested and documented patches or detailed bug reports.

Otherwise you can "flattr" me: Flattr the Argh project


Argh is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Argh is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Argh. If not, see <>.