A great place to look for examples of how to use the Splunk SDK for Python is in the unit tests. These are the same tests that we used to validate the core SDK library.
The test suite uses Python's standard library and the built-in unittest library. If you're using Python 2.7, you're all set. However, if you are using Python 2.6, you'll also need to install the unittest2 library to get the additional features that were added to Python 2.7 (just run pip install unittest2 or easy_install unittest2).
To run the unit tests, open a command prompt in the /splunk-sdk-python directory and enter:
python setup.py test
You can also run individual test files, which are located in /splunk-sdk-python/tests. For example, to run the apps test, open a command prompt in the /splunk-sdk-python/tests subdirectory and enter:
Coverage.py is an excellent tool for measuring code coverage of Python programs.
To install it, use Easy Install:
Or use pip:
pip install coverage
To generate a report of the code coverage of the unit test suite, open a command prompt in the /splunk-sdk-python directory and enter:
python setup.py coverage
This command runs the entire test suite and writes an HTML coverage report to the /splunk-sdk-python/coverage_report directory.
For more information about Coverage.py, see the author's website (http://nedbatchelder.com/code/coverage/).