skip to navigation
skip to content

subcomm 0.3.1

A command subparser utility.

Subcomm provides a clear API for creating subcommands.

Supports Python: 3.3, 3.4, 3.5, 3.6


$ pip install subcomm

Basic usage

Create the command parser:

parser = SubcommParser(description='Command parser.')

When declaring commands, use the @parser.command decorator:

@parser.command(help='Run the command start.')
def start(args):
    return 0

You can customize the subparser by accessing it as an attribute of the function: start.parser, so you can add arguments to the subcommand or any other parser behavior using the default argparse API.

You call the handlers by doing:

The value returned by the handler will be returned to the caller. If you are running a script and you want to return something consistent with the return values of the handlers, do:


If the code is in a script called, then you can run it using:

python command

That’s the same thing as calling the command function.

If you want a default command, so you can just call python, then you can declare:

@parser.default(help='Help for the subcommand.')
def start(args):

You can only declare one default command at a time.

Asserting code quality

Of course we use our own API, so:

$ python quality

Running tests

$ python test

This will report code coverage as well.

To run tests with tox, run:

$ tox

Packaging for PyPI distribution

$ python package

The build will happen if the repository is clean: no untracked files are found. If not, you can see what’s wrong with git clean -dfx --dry-run and remove or track and commit those files.

Builds will be available at dist, in wheel and source.


Pull requests are welcome.

File Type Py Version Uploaded on Size
subcomm-0.3.1-py3-none-any.whl (md5) Python Wheel py3 2017-08-11 4KB
subcomm-0.3.1.tar.gz (md5) Source 2017-08-11 3KB