Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

Effortless argument parsing

Project Description

defopt allows you to effortlessly call Python functions from the command line.

defopt will:

  • Allow functions to be called identically from code or the command line
  • Reward you for documenting your functions
  • Produce informative command line help messages
  • Save you from writing and maintaining argument parsing code ever again

defopt will not:

  • Modify your functions in any way
  • Allow you to build complex command line tools (try docopt or click)

Usage

Once you have written and documented your main function (currently you must use Sphinx-style docstrings), simply decorate it with @defopt.main, then call defopt.run() to see the magic happen.

import defopt

@defopt.main
def main(greeting, count=1):
    """Display a friendly greeting.

    :param str greeting: Greeting to display
    :param int count: Number of times to display the greeting
    """
    for _ in range(count):
        print(greeting)

if __name__ == '__main__':
    defopt.run()

This function can now be called identically from Python and the command line.

>>> from test import main
>>> main('hello!', count=2)
hello!
hello!
$ python test.py hello! --count 2
hello!
hello!

Development

For source code, examples, questions, feature requests and bug reports, visit the GitHub repository.

Release history Release notifications

History Node

4.0.1

History Node

4.0.0

History Node

3.2.0

History Node

3.1.1

History Node

3.0.0

History Node

2.0.1

History Node

2.0.0

History Node

1.3.0

History Node

1.2.0

History Node

1.1.0

History Node

1.0.1

History Node

1.0.0

History Node

0.3.1

This version
History Node

0.3.0

History Node

0.2.0

History Node

0.1.0

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
defopt-0.3.0-py3-none-any.whl (6.6 kB) Copy SHA256 hash SHA256 Wheel 3.5 Feb 10, 2016
defopt-0.3.0.zip (20.9 kB) Copy SHA256 hash SHA256 Source None Feb 10, 2016

Supported by

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