Skip to main content

argparser factory for miniconfig

Project description

argparse settings with miniconfig


from miniconfig_argparse import get_configurator

config = get_configurator()

args = config.make_args()
# using args

in yourmodule, using config like a below.

def includeme(config):
    parser = config.parser

        '-v', '--verbose', action='count', default=0,
        help="(default option: increment logging level(default is WARNING))"
        '-q', '--quiet', action='count', default=0,
        help="(default option: decrement logging level(default is WARNING))"

    def setup_closure(args):
        logging_level = logging.WARN + 10 * args.quiet - 10 * args.verbose
        return args


default directives

  • make_parser
  • replace_parser
  • call_function_as_command

make_parser(fn) + call_function_as_command

Using make_parser() and call_function_as_command() combinations are useful, sometimes.

  • make_parser(fn) – creating parser from a function definition.
  • call_function_as_command – call function using parsed argument object.

Such as below.

def greeting(message, is_surprised=False, name="foo"):
    """ greeting message

    :param message: message of greeting
    :param is_surprised: surprised or not (default=False)
    :param name: name of actor
    suffix = "!" if is_surprised else ""
    print("{name}: {message}{suffix}".format(name=name, message=message, suffix=suffix))

def includeme(config):
    parser = config.make_parser(greeting)

if __name__ == "__main__":
    from miniconfig_argparse import get_configurator
    config = get_configurator()

    args = config.make_args()
    config.call_function_as_command(greeting, args)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
miniconfig-argparse-0.0.4.tar.gz (4.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page