Skip to main content

Making argument parsing easy

Project description

https://travis-ci.org/stedmeister/easyargs.svg?branch=master

easyargs

A project designed to make command line argument parsing easy.

It is used as follows:

import easyargs

@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__':
    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 simple.py -h
usage: simple_test.py [-h] [--count COUNT] [--greeting GREETING] name

A simple greeting program

positional arguments:
  name

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 simple.py World
Hello World

$ python simple.py 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.

Source Distribution

easyargs-0.8.2.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

easyargs-0.8.2-py2.py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page