Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Installation follows the same steps as plac. If you are lazy, just perform

$ pip install plac_ini

which will install the module on your system (and possibly argparse too, if it is not already installed).

If you prefer to install the full distribution from source, including the documentation, download the tarball, unpack it and run

$ python install

in the main directory, possibly as superuser.


Still working on tests!


The plac_ini module adds configuration file (INI) parsing to the plac module. The plac module is a tool for building command line interfaces using Python.

As with plac, the approach is to define a function in Python, annotate it using either the plac.annotations dectorator or Python 3's native annotations, then use (rather than to call your function. With, you will also provide the path to a configuration file that can be used to set options and optionally a default INI section.


#!/usr/bin/env python

import os
import plac
import plac_ini

# (help, kind, abbrev, type, choices, metavar)
    user_name=('Git username', 'option', 'u', None, None, 'USER_NAME'),
    user_email=('Git email', 'option', 'e', None, None, 'EMAIL'),
    color_ui=('UI Color', 'option', 'c', None, None, 'COLOR_UI'),
    push_default=('push_default', 'option', 'p', None, None, 'PUSH')
def main(user_name=None,
    print("user_name {}".format(user_name))
    print("user_email {}".format(user_email))
    print("color_ui {}".format(color_ui))
    print("push_default {}".format(push_default))

if __name__ == '__main__':
    gitconfig = os.path.join(os.path.expanduser('~'), '.gitconfig'), config=gitconfig)

My ~/.gitconfig looks like the following.

    name = Brent Woodruff
    email =
    default = simple

So here are the results of a few different kinds of runs.

$./gitstuff -h
usage: gitstuff [-h] [-u USER_NAME] [-e EMAIL] [-c COLOR_UI] [-p PUSH]

optional arguments:
  -h, --help            show this help message and exit
  -u USER_NAME, --user-name USER_NAME
                        Git username
  -e EMAIL, --user-email EMAIL
                        Git email
  -c COLOR_UI, --color-ui COLOR_UI
                        UI Color
  -p PUSH, --push-default PUSH
user_name Brent Woodruff
color_ui auto
push_default simple
$./gitstuff -c true --push-default nothing
user_name Brent Woodruff
color_ui true
push_default nothing

A few items of note:

  • Defaults are specified in the function specification.
  • Defaults are overridden by entries in the config file.
  • Defaults and config file entries are overridden by command line options.
  • The config file will parse options into 'section_item' style names. A default section can be given which will be parsed back without the 'section_'.
  • If the config file is not found, will try to proceed with defaults and command line options.
  • Only items that are specified by the function definition will be provided. That is, if a config file has many more sections and items, they will not be provided in the argument list.
  • All things that plac can do, hopefully plac_ini works with, so reference that documentation and send me bug reports. I am going to work on tests.
  • Speaking of plac features, plac_ini supports the conversion of types as specified in the annotations. Boolean types are a special case, as those are converted using ConfigParser._convert_to_boolean, which supports things like 1, yes, true, and more for True / False values.
  • The code is written to be compatible with If 'config=FILEPATH' is not given, then just calls I've done this so the code would be easier to include in plac proper in the future.

The source code is hosted on Github.\_ini


Define a function, get an argument parser and config file parser for free.







No releases published


No packages published