API:Client code

Overview
Client libraries contain code that developers can use to help with common and basic tasks, so that they don't have to write the code from scratch when their projects interact with an API. Developers use client libraries that are written in the language they are using for their project.

This page contains a set of lists, by language, of client libraries that can be used with the MediaWiki Action API.

Awk
Dates and version numbers were updated on 2018-05-30.
 * BotWikiAwk. Framework and libraries for creating bots. Includes example bots.
 * Wikiget. Awk CLI program to interface with MediaWiki API for read/write including OAuth.

C++
Dates and version numbers were updated on 2017-08-01.
 * libmediawiki. There is a tutorial in KDE TechBase. Last activity: 2017-04-01.

Common Lisp
Dates and version here were updated 2017-08-01.
 * cl-mediawiki is a Common Lisp wrapper for the mediawiki API. It is available as a direct download, or (more conveniently) via quicklisp. Last activity: 2016-11-10.

Go
Dates and version numbers were updated on 2018-08-05.
 * go-mediawiki Go wrapper for the MediaWiki API. Last activity: 2017-02-07.
 * go-mwclient another Go wrapper for the MediaWiki API (supports maxlag, query continuations, OAuth). Last release: 1.0.3, 2018-08-03.

Haskell
Dates and version numbers were updated on 2017-08-01.
 * haskell mediawiki. Last activity: November 2013.

Java
Dates and version numbers were updated on 2018-03-15. Last activity refers to the last commit in the repository, which is useful to know if it is still active (and sometimes there are no "official" releases).

JavaScript
Dates and version numbers were updated on 2017-08-06. Last activity refers to the last commit in the repository, which is useful to know if it is still active (and sometimes there are no "official" releases).

In-wiki JavaScript clients
Dates and version numbers were updated on 2017-08-06. Last activity refers to the last commit in the repository, which is useful to know if it is still active (and sometimes there are no "official" releases).

Lua

 * dtMediaWiki/mediawikiapi.lua makes query (tokens, userinfo), clientlogin, upload, and logout calls. It handles HTTPS requests and cookies and can be used to upload files to Wikimedia Commons.

MATLAB

 * MatWiki - a preliminary (as of Feb 2019) MATLAB R2016b(9.1.x) client supporting just bot-logins & semantic #ask queries.

.NET

 * AutoWikiBrowser's WikiFunctions library has classes for editing and getting lists of pages via the API. See ApiEdit
 * DotNetWikiBot Framework - written in C#, based on Microsoft® .NET Framework 3.5 (Tutorial)
 * MorebitsDotNet contains C# code for uploading files through the API.
 * LinqToWiki, strongly typed library for accessing most of MediaWiki API, with support for autocompletion
 * WikiClientLibrary - A .NET Standard & asynchronous MediaWiki API client library for wiki sites. The library also supports Flow/Wikibase/Wikia-specific API. Last update: July 2018.

OCaml

 * ocaml-mediawiki

Perl

 * MediaWiki::Bot - A higher-level Perl module with read and write functions. Easily extensible with plugins, for example to provide administrator functions. Updated Jan 2014. (Evaluation)
 * source code on Github


 * MediaWiki::API - A Perl module for interfacing with the MediaWiki API with file upload/download and editing support. Updated Nov 2015. (Debian package). (Evaluation)

PHP
There are many PHP frameworks for the api, see here for a full list and comparison of frameworks.
 * Apibot - a modular, somewhat ambitious bot with overlayed UNIX-like framework
 * addwiki, actively maintained as of July 2017, comprised of several libraries:
 * mediawiki-api-base - Library for basic MediaWiki api use
 * mediawiki-api - Library for querying MediaWiki
 * wikibase-api - Library for querying Wikidata
 * wikidrain - A wrapper for the WikiMedia API centralized around easily and simply querying Wikipedia articles. (Still actively being developed as of April 2014)
 * MediaWiki_Api - A simple PHP curl based API wrapper with basic functionality. Almost completely undocumented.
 * Wikimate - Gets and edits MediaWiki pages, actively maintained as of October 2016.

Sometimes people try to use this kind of libraries to access a MediaWiki installation on the same server. This is often unnecessary because MediaWiki itself is written in PHP, especially when the only purpose of the script is interacting with MediaWiki. By 'ing  (  may need to be set beforehand, see Manual:$IP), a script gets access to MediaWiki components and consequently it can call the API internally or use other MediaWiki classes and functions directly, which greatly reduces server load.

Python

 * - A collection of python scripts and a powerful library for bot writing. Actively maintained since 2003. (Git repository) (IRC) (Evaluation)
 * [//github.com/mwclient/mwclient mwclient] - A Python library that makes most of the API functions accessible. Last release: v0.9.3, November 2018. ([//pypi.python.org/pypi/mwclient/ PyPI]) (Evaluation)
 * Wikipedia-API - Easy to use Python 3 library. Provides read-only API. Last release: v0.4.3, January 2019. ([//pypi.python.org/pypi/Wikipedia-API/ PyPI])([//wikipedia-api.readthedocs.io/ Docs])
 * ceterach - Python3 library, fully PEP8 compliant. Last updated in March 2018.
 * wptools - Wikipedia tools (for Humans). Read-only API. Actively maintained (2018). (Docs)
 * wiki-scripts - Framework for writing bots, maintenance scripts or performing data analysis. Actively maintained (2018). (Docs)
 * Pattern (GitHub) - web mining module, has classes for handling MediaWiki API requests, handles continuations. Last updated in August 2017.

Simple wrappers (no-abstraction interfaces to the MediaWiki API, basic session handling):
 * [//github.com/ianweller/python-simplemediawiki simplemediawiki] - Python 2.6+ and 3.3+ compatible. Docs. Last updated in March 2017. ([//pypi.python.org/pypi/simplemediawiki PyPI]) (Evaluation)
 * [//github.com/yuvipanda/python-mwapi python-mwapi] - Last updated in March 2017. ([//pypi.python.org/pypi/python-mwapi PyPI])
 * async_mediawiki - An asynchronous wrapper. Last updated in June 2018. ([//pypi.org/project/async-mediawiki/ PyPI])

No updates after 2016:
 * analytics-zero-sms - Last updated in October 2015.
 * wiki-api - access to Wikipedia.org's search results and article content. Last updated in July 2015. ([//pypi.python.org/pypi/wikitools PyPI]) (Evaluation)
 * mwstreaming Last updated in April 2015.
 * Wikipedia -  A Python library that makes it easy to access and parse data from Wikipedia. Last updated in November 2016. (PyPI)
 * wikitools - Provides several layers of abstraction around the API. Doesn't support Python 3. Last updated in August 2016.

See also:
 * API:Edit/Editing with Python

R

 * WikipediR - a read-only API wrapper.

Ruby

 * mediawiki/ruby/api (GitHub mirror), Mediawiki Ruby API (Gerrit master repo) - Ruby API client library in active development by Wikimedia Foundation Release Engineering as of January 2015
 * MediaWiki::Gateway - Ruby framework for the API. Maintained (as of January 2015) but not actively developed; patches are welcome. Tested up to MediaWiki 1.23, compatible with Wikimedia wikis.  Currently incompatible with new   system. (Evaluation)
 * wikipedia-client - Ruby framework using the API.
 * Sunflower - Provides Ruby access to MediaWiki API; can be used as a base for more sophisticated bots or as standalone by beginners
 * MediaWiki::Butt - Stable but powerful Ruby framework for the API in active development. (Evaluation)
 * MediaWiktory (low-level) and Infoboxer (high-level, semantic) clients to MediaWiki, with idiomatic API, support for custom Wiki modules, in active development.

Rust

 * mediawiki-rs - Wrapper for the MediaWiki API. Last updated June 2018.
 * WP:RS - An extremely low-level wrapper to the MediaWiki API. Last updated June 2017.
 * Wikibase RS - Rust library to talk to the Wikibase API and serialize data into Rust data structures.

Scala

 * scalawiki by User:Ilya
 * dbpedia extraction framework data extraction framework for DBpedia with support Wiki source retrived via MediaWiki API
 * scmw Simple MediaWiki API wrapper for needs of Commonist image upload tool

Reduce bandwidth usage

 * Use GZip compression when making API calls.
 * Ask for multiple items in one request, to minimize the number of API calls.
 * Use  and get all the needed lists and properties at the same time.

Set a User-Agent header
It is best practice, but not required to set a descriptive User Agent header. To do so, use
 * Include your username and wiki or email address.

Data formats
All new API users should use JSON. XML and PHP are currently supported but discouraged.

Comparing clients
API:Client code/Gold standard describes best practices for action API client libraries.