termtool API Reference

termtool.subcommand([help], **kwargs)

A decorator (that is, returns a decorator) to mark a function as a Termtool subcommand. Arguments are passed to the argparse.ArgumentParser constructor, so any of its arguments are valid keyword arguments.

termtool.argument(name or flags...[, help], **kwargs)

A decorator (that is, returns a decorator) to declare an argument of a subcommand method or command class. Arguments are passed to the argparse.ArgumentParser.add_argument() method of the command’s argparse.ArgumentParser instance, so any of its arguments are valid.

class termtool.Termtool

Creates a new Termtool instance. Make your own command line tool by subclassing this class and defining new subcommands with the subcommand() decorator.

table([field_names], **kwargs)

Returns a new prettytable.PrettyTable instance.

Any arguments for the prettytable.PrettyTable constructor are valid arguments to table(). See the prettytable documentation for more information.

progressbar([max_val], **kwargs)

Returns a new progressbar.ProgressBar instance.

Any arguments for the progressbar.ProgressBar constructor are valid arguments to progressbar(). See the progressbar documentation for more information.


Reads any additional arguments saved in the user’s configuration file for the tool and returns them as a list.

Configuration files are files in the user’s home directory named .toolname where toolname is the name of the tool class in lower case. The file if present should contain arguments one per line.


Replaces the user’s configuration file with the arguments present in config_args.

This method will overwrite any unexpected changes the user has made to the configuration file, so only use it in response to an explicit instruction by the user, such as in a configure command. If the file is created, it is created with umask 077 so that it is neither group nor world readable.


Invokes the tool with the specified command line arguments, returning the appropriate exit code.

main() first reads the “rc” style configuration file, prepending its arguments to argv before the other arguments. The arguments are then parsed and the logging module is first configured. main() then dispatches to the instance method matching the subcommand specified by the first positional argument in argv.


Invokes the tool as run from a script.

Command line arguments are read from sys.argv. When the tool’s run is complete, run() exits the interpreter using sys.exit() with an appropriate exit code (0 if the run completed normally and a non-zero value otherwise) when complete.

Use this method in your if __name__ == '__main__' block.

Project Versions

Previous topic

termtool guide

This Page