Skip to main content

Making argument parsing easy

Project description

A project designed to make command line argument parsing easy.

It is used as follows:

import easyargs

def main(name, count=1, greeting='Hello'):
    """A simple greeting program"""
    for i in range(count):
        print '{greeting} {name}!'.format(greeting=greeting, name=name)

if __name__ == '__main__':

In this (rather contrived) example, main will be inspected and the arg keywords will be turned into positional arguments and the kwarg keywords will be turned into optional arguments. This can be seen if we run the above script with the help flag:

$ python -h
usage: [-h] [--count COUNT] [--greeting GREETING] name

A simple greeting program

positional arguments:

optional arguments:
  -h, --help           show this help message and exit
  --count COUNT
  --greeting GREETING

Note are that program description is automatically created based on the docstring of the function. Also note that the type of the default value is inspected so that the value of count is coerced to an integer:

$ python World
Hello World

$ python everybody --count 2 --greeting Hola
Hola everybody!
Hola everybody!

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 easyargs, version 0.8.0
Filename, size File type Python version Upload date Hashes
Filename, size easyargs-0.8.0-py2.py3-none-any.whl (5.2 kB) File type Wheel Python version py2.py3 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