Application with bindings for commands

Quick demo:

>>> import sample
>>> from import CliApplication, argument
>>> app = CliApplication(sample)
>>> @argument('--verbose', target='verbose', action='store_true')
>>> @app.command()
>>> def hello(opts):
...     if opts.verbose:
...         print("Being verbose!")
...     print("Hello")

>>> if __name__ == '__main__':
...     app.dispatch()

This example provides an application with a command hello that takes an optional verbose flag. The framework also provides help, configures and loads settings (using pyapp.conf), an interface to the checks framework and configures the Python logging framework.

There are however a few more things that are required to get this going. The CliApplication class expects a certain structure of your application to allow for it’s (customisable) defaults to be applied.

Your application should have the following structure:

my_app/          # Include a __version__ variable          # This is where the quick demo is located  # The default settings file


class, *, prog: str = None, description: str = None, epilog: str = None, version: str = None, ext_white_list: Sequence[str] = None, application_settings: str = None, application_checks: str = None, env_settings_key: str = None, env_loglevel_key: str = None)[source]

Application interface that provides a CLI interface.

  • root_module – The root module for this application (used for discovery of other modules)
  • prog – Name of your application; defaults to sys.argv[0]
  • description – A description of your application for –help.
  • version – Specify a specific version; defaults to getattr(root_module, ‘__version__’)
  • ext_white_list – Sequence if extensions that are white listed; default is None or all extensions.
  • application_settings – The default settings for this application; defaults to root_module.default_settings
  • application_checks – Location of application checks file; defaults to root_module.checks if it exists.
  • env_settings_key – Key used to define settings file in environment.
  • env_loglevel_key – Key used to define log level in environment
command(handler: Callable[[argparse.Namespace], Optional[int]] = None, *, name: str = None, aliases: Sequence[str] = (), help_text: str = None) →

Decorator for registering handlers.

  • handler – Handler function
  • name – Optional name to use for CLI; defaults to the function name.
  • aliases – A sequence a name aliases for this command command.
  • help_text – Information provided to the user if help is invoked; default is taken from the handlers doc string.
create_command_group(name: str, *, aliases: Sequence[str] = (), help_text: str = None) →

Create a command group

  • name – Name of the command group
  • aliases – A sequence a name aliases for this command group.
  • help_text – Information provided to the user if help is invoked.
default(handler: Callable[[argparse.Namespace], Optional[int]])

Decorator for registering a default handler.

dispatch(args: Sequence[str] = None) → None[source]

Dispatch command to registered handler.


Wrappers around argparse to provide a simplified interface