API:Client code

From MediaWiki.org
(Redirected from API:Client Code)
Jump to navigation Jump to search
Other languages: English  • 日本語 • русский

Overview[edit]

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.

API client libraries[edit]

Awk[edit]

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++[edit]

Dates and version numbers were updated on 2017-08-01.

Common Lisp[edit]

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[edit]

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[edit]

Dates and version numbers were updated on 2017-08-01.

Java[edit]

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).

Name Description Last release Release Date Last activity
Bliki Engine Can convert wikicode to HTML, DocBook or PDF. Has a helper library for API calls February 22, 2018
DKPro Collection of Natural Language Processing open-source projects started by the German university of Darmstadt. Authors of dkpro-jwpl (Java Wikipedia Library) and dkpro-jwktl (Java Wiktionary Library). 1.1.0 April 24, 2016 March 3, 2018
JavaWikiBotFramework A library that makes several API functions accessible. (Evaluation) 3.1.0 December 11, 2014 March 6, 2018
jwiki A library which makes it so easy to use the API that even your grandma 👵🏻 could do it. 1.5.0 January 6, 2018 March 14, 2018
Kaspar Framework for editing MediaWiki wikis. 0.2 July 18, 2015 January 14, 2016
Mediawiki-Japi An API for the MediaWiki web API. 0.0.22 January 25, 2018 January 25, 2018
Wiki.java A MediaWiki bot framework. 0.34 January 13, 2018 March 1, 2018
Wikidata Toolkit A library with functions to process data from Wikidata and other Wikibase sites, via XML dumps or the API. For more info, see Wikidata Toolkit. 0.8.0 December 18, 2017 March 13, 2018
WPCleaner WPCleaner is a tool designed to help with various maintenance tasks on wikis run with MediaWiki software. February 21, 2018

JavaScript[edit]

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).

Name Description Last release Release Date Last activity
wikidata-sdk (Node.js) Wikidata SDK is a javascript toolkit for querying Wikidata.org and simplify its results. 5.1.4 2017-04-01 2017-06-10
mwbot (Node.js) MWBot uses the Promise pattern and other ES6 methodologies, optimised for creating bots that make edits. Works with any MediaWiki site. 1.0.10 2017-07-25 2018-03-06
wikijs (Node.js) WikiJs provides a high-level interface for editing, querying and searching through the API. Works with any MediaWiki site. 3.2.0 2017-08-02 2017-08-02
nodemw (Node.js) nodemw is a generic MediaWiki API client for Node.js.  0.12.0 2016-06-04 2018-02-06
mediawiki (Node.js) This JavaScript framework provides methods for common use cases (e.g. log in, read, edit, etc.) as well as a generic API client. Includes handling for rate throttling. 2014-07-02
mediawiki.api (browser) Generic MediaWiki API client for client-side JavaScript. It ships with MediaWiki core as a ResourceLoader module bundle. It abstracts some high-level concepts and provides a generic client for other queries. Maintained as part of MediaWiki.
mediawiki-js (browser) Ultra-light, vanilla JavaScript wrapper of Mediawiki API for use in the browser (npm) 2015-06-17
CeJS (Node.js, browser) A JavaScript framework including MediaWiki functions to build bots, running on Node.js and in the browser. See Wikipedia bot examples. 2.0.0 2015-10-28 2017-08-04

In-wiki JavaScript clients[edit]

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).

Name Description Last release Release Date Last activity
mwapilib2 A layer overtop of the requests. Make JS gadgets easier. 2016-09-25
JsMwApi A convenience wrapper around raw requests, with some helpers for editing and parsing. 2014-06-11

Lua[edit]

  • 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[edit]

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

.NET[edit]

  • 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[edit]

Perl[edit]

PHP[edit]

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:
  • 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 require'ing WebStart.php (MW_INSTALL_PATH 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[edit]

  • Pywikibot - A collection of python scripts and a powerful library for bot writing. Actively maintained since 2003. (Git repository) (IRC) (Evaluation)
  • mwclient - A Python library that makes most of the API functions accessible. Last release: v0.9.3, November 2018. (PyPI) (Evaluation)
  • Wikipedia-API - Easy to use Python 3 library. Provides read-only API. Last release: v0.4.3, January 2019. (PyPI)(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):

  • pywikiapi - A minimalistic library that handles some of the core MediaWiki API complexities like handling continuations, login, errors, and warnings, but does not impose any additional abstraction layers, allowing the usage of every single feature of the MW API directly in the most optimal way. From the original author of the MW API itself. Last updated in December 2018.
  • simplemediawiki - Python 2.6+ and 3.3+ compatible. Docs. Last updated in March 2017. (PyPI) (Evaluation)
  • python-mwapi - Last updated in March 2017. (PyPI)
  • async_mediawiki - An asynchronous wrapper. Last updated in June 2018. (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) (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:

R[edit]

Ruby[edit]

  • 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 continue 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[edit]

  • mediawiki-rs - Wrapper for the MediaWiki API.
  • WP:RS - An extremely low-level wrapper to the MediaWiki API.
  • Wikibase RS - Rust library to talk to the Wikibase API and serialize data into Rust data structures.
  • mediawiki_rust - A MediaWiki client library in Rust

Scala[edit]

Making API calls[edit]

Reduce bandwidth usage[edit]

  • Use GZip compression when making API calls (Accept-Encoding: gzip).
  • Ask for multiple items in one request, to minimize the number of API calls.
    • Use titles=PageA|PageB|PageC and get all the needed lists and properties at the same time.

Set a User-Agent header[edit]

It is best practice, but not required to set a descriptive User Agent header. To do so, use (User-Agent: User name/email/framework/...)

Include your username and wiki or email address.

If you are calling the API from browser-based JavaScript, you may not be able to influence the User-Agent header (depending on the browser). To work around this, use the Api-User-Agent header:

In PHP, you can identify your user-agent with code such as this:

Data formats[edit]

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

Comparing clients[edit]

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


See also[edit]