Skip to main content

A command subparser utility.

Project description

Subcomm provides a clear API for creating subcommands.

Supports Python: 3.5, 3.6, 3.7


$ 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(file):
    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. Arguments will be passed to the command handler by the names they would have in parser.parse_args().

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.


Install for development and with dependencies:

$ pip install -e .[dev]

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 passes the quality tests and 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.

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 subcomm, version 0.3.3
Filename, size File type Python version Upload date Hashes
Filename, size subcomm-0.3.3-py3-none-any.whl (4.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size subcomm-0.3.3.tar.gz (4.2 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