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!
To use your defopt command line as a setuptools console entry point, call defopt.run() from within your module.
setup( ..., entry_points={'console_scripts': ['test=test:defopt.run']} )
Development
For source code, examples, questions, feature requests and bug reports, visit the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for defopt-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dab7bce395284741511c2797fe631256d8f18d68fb791e1c171200f02b2c6f6 |
|
MD5 | cc8f1361110f7fdde3fad964116a95f4 |
|
BLAKE2b-256 | a07fca967d8827d1c1a0c44721c83de73367c2da01408ea820865e806ad3ea70 |