Effortless argument parser
defopt is a lightweight, no-effort argument parser.
defopt will not:
If you want total control over how your command line looks or behaves, try docopt, click or argh. If you just want to write Python code and leave the command line interface up to someone else, defopt is for you.
Once you have written and documented your function, simply pass it to
defopt.run() and you’re done.
import defopt 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(main)
Descriptions of the parameters and the function itself are used to build an informative help message.
$ python test.py -h usage: test.py [-h] [-c COUNT] greeting Display a friendly greeting. positional arguments: greeting Greeting to display optional arguments: -h, --help show this help message and exit -c COUNT, --count COUNT Number of times to display the greeting (default: 1)
Your 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!
defopt was developed with the following guiding principles in mind:
For source code, examples, questions, feature requests and bug reports, visit the GitHub repository.
Documentation is hosted on Read the Docs.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|defopt-3.2.0-py2.py3-none-any.whl (10.9 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||May 30, 2017|
|defopt-3.2.0.tar.gz (26.8 kB) Copy SHA256 Checksum SHA256||–||Source||May 30, 2017|