Skip to main content

Additional classes for argparse

Project description

Python argparse.ArgumentParser subclass(es)

Quick example of argparser declaration from dictionary:

import sys
from argparse.extra import DictArgumentParser

def run_testarg_processing(args, argv):
    print 'testarg argument used'

ARGUMENTS = {'--use-something':{'dest':'use_something',
                 #sub:testarg will create subparser 'testarg'
                 #depth of subargs is unlimited
                 'description':'Test arg subcommand',
                 'help':'Test help'

DEFAULTS_ONLY = ['func',]
def get_argparser(argsdict=ARGUMENTS):
    #always create get_argparser function for your cli apps
    #this will enable easy integration of subsequent applications
    #with your argparser
    return DictArgumentParser(argsdict, DEFAULTS_ONLY)

def main(args=sys.argv):
    args, argv = get_argparser().parse_known_args(args[1:])
    args.func(args, argv)

if __name__ == '__main__':


Try one of these:

python install

easy_install argparse.extra

pip install argparse.extra

Project details

Download files

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

Files for argparse.extra, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size argparse.extra-0.0.2-py2.7.egg (6.6 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size argparse.extra-0.0.2.tar.gz (122.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page