The Argcomplete Extension provides the necessary hooks to utilize the Argcomplete Library, and perform auto-completion of command line arguments/options/sub-parsers/etc.


  • Argcomplete (pip install argcomplete)
  • Argparse

This extension currently only works when using cement.ext.ext_argparse.ArgparseArgumentHandler (default) and cement.ext.ext_argparse.ArgparseController (new in Cement 2.8). It will not work with cement.core.controller.CementBaseController.


This extension does not honor any application configuration settings.



#!/usr/bin/env python

from cement.core.foundation import CementApp
from cement.ext.ext_argparse import ArgparseController, expose

class BaseController(ArgparseController):
    class Meta:
        label = 'base'
        arguments = [
            (['-f', '--foo'], dict(help='base foo option', dest='foo'))

    def default(self):
        print('Inside BaseController.default')

    def command1(self):
        print('Inside BaseController.command1')

class MyApp(CementApp):
    class Meta:
        label = 'myapp'
        extensions = ['argcomplete']
        handlers = [BaseController]

with MyApp() as app:

Note the #! line, which allows us to call our script directly (specifically for this example). The Argcomplete library requires the end-user to modify their environment in order to perform auto-completion. For this example, we are using a non-global option for demonstration purposes only. In the real world you will need to setup Argcomplete for your actual application entry-point name (i.e. myapp if installed as /usr/bin/myapp, etc).

$ eval "$(register-python-argcomplete myapp.py)"

$ ./myapp.py [tab][tab]

--debug                              -h
-o                                   --help
--quiet                              command1

See the Argcomplete Documentation on how to properly integrate it’s usage into your application deployment. This extension simply enables Argcomplete to do it’s thing on application startup.