API:Client Code/Access Library Comparison

Initial microtask for Evaluating MediaWiki web API client libraries.

The Python libraries listed on API:Client Code fall into two groups: libraries that offer a layer of abstraction that makes it easy for programmers to take advantage of the internal structure of the Mediawiki instance, and simple API wrappers that handle functions like logging in and cookies but do not otherwise mask the API structure.

Libraries that provide layers of abstraction over the MediaWiki API:

 * (IRC)
 * [//github.com/mwclient/mwclient mwclient] ([//pypi.python.org/pypi/mwclient/ PyPI])
 * wikitools ([//pypi.python.org/pypi/wikitools PyPI])
 * Wikipedia (PyPI)
 * Documentation warns not to use this for bots; does not support rate-limiting and other important features.

Simple wrappers for the MediaWiki API:

 * [//github.com/ianweller/python-simplemediawiki simplemediawiki] ([//pypi.python.org/pypi/simplemediawiki PyPI])
 * Handles cookies, login
 * Requires Python 2.6+ or 3.3+
 * Includes a documentation build configuration file, but no separate documentation
 * Provides usage examples in comments
 * Includes unit tests
 * Last updated: March 2014


 * [//github.com/legoktm/supersimplemediawiki supersimplemediawiki]
 * Handles login, cookies, get, post, and API calls
 * Python 2.6-3.3 compatible
 * Has an example script, but no other documentation.
 * No tests provided
 * Last updated: Nov 2013


 * [//github.com/yuvipanda/python-mwapi python-mwapi] ([//pypi.python.org/pypi/python-mwapi PyPI])
 * Handles login, get, post
 * Minimal documentation; no usage examples provided
 * No tests provided
 * Last updated: Dec 2012

The simplemediawiki is the only one of these basic API client libraries actively maintained (as of March 2014) and it is now compatible with Python 3. It is the best documented and is the only one that includes unit tests. The documentation could be improved by writing a more in-depth introduction to the library, making the example code easier to find and better documented, and including a separate documentation file. Simplemediawiki makes it easy to create a user_agent string, handles login and cookies, and provides a Python interface for making API calls (including the relatively recent Wikibase extension wbsearchentities).

First tests: getting data, no login/token needed

 * Make sure that the API call you're making is supported on the wiki you're interacting with.  is available on Wikidata, not on Mediawiki.


 * Get calls work now that they are being called on the correct API! For instance:

Corresponding API request in browser:

http://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&search=abc&language=en

Result:


 * results for a missing page:

Testing login, tokens, editing

 * Testing login capabilities and namespaces:

Conclusion: namespaces works, login returns True, and the userinfo query would not be possible without the logged in bot.


 * Testing the 'edit' API call:

The existing text of Project:Sandbox of "hello everyone" has been replaced with "hello everyone else", as directed.

Note that cache issues may mean that these changes do not appear when reloading the page in the browser.

First tests
leads to the following error message, rather than the text of the sandbox page with an added "woohoo!":
 * The save method requires logging in. Adding the following lines to the end of the above script

The login functions have not been tested yet but are the next step. mwclient has also not been tested to determine whether the more recent wikibase-related API calls are made accessible.