#mediawiki #api

mwapi

A MediaWiki API client library

14 unstable releases (3 breaking)

Uses new Rust 2021

0.4.0-alpha.2 Jan 4, 2022
0.4.0-alpha.1 Dec 24, 2021
0.3.1 Nov 20, 2021
0.3.0-alpha.4 Oct 21, 2021
0.1.0 Jun 18, 2021

#2 in #mediawiki

Download history 4/week @ 2021-09-27 198/week @ 2021-10-04 112/week @ 2021-10-11 44/week @ 2021-10-18 3/week @ 2021-10-25 50/week @ 2021-11-01 57/week @ 2021-11-08 64/week @ 2021-11-15 21/week @ 2021-11-22 36/week @ 2021-11-29 16/week @ 2021-12-06 25/week @ 2021-12-13 31/week @ 2021-12-20 7/week @ 2021-12-27 48/week @ 2022-01-03 14/week @ 2022-01-10

100 downloads per month
Used in mwbot

GPL-3.0-or-later

63KB
1K SLoC

mwapi

crates.io docs.rs pipeline status coverage report

See the full documentation (docs for master).

License

mwapi is (C) 2021 Kunal Mehta, released under the GPL v3 or any later version, see COPYING for details.


lib.rs:

A MediaWiki API client library.

mwapi is a low-level library for the MediaWiki Action API. If you intend to edit pages or want a higher-level interface, it's recommended to use mwbot, which builds on top of this crate.

Goals

  • generic to fit any application, whether for interactive usage or writing a bot
  • fully compatible with concurrent use cases
  • turns MediaWiki errors into Rust errors for you
  • logging (using the tracing crate) for visiblity into errors
  • follow all best practices

Quick start

# #[tokio::main]
# async fn main() -> mwapi::Result<()> {
let client = mwapi::Client::builder("https://en.wikipedia.org/w/api.php")
    .set_user_agent("mwapi demo")
    // Provide credentials for login:
    // .set_botpassword("username", "password")
    .build().await?;
let resp = client.get_value(&[
    ("action", "query"),
    ("prop", "info"),
    ("titles", "Taylor Swift"),
]).await?;
let info = resp["query"]["pages"][0].clone();
assert_eq!(info["ns"].as_u64().unwrap(), 0);
assert_eq!(info["title"].as_str().unwrap(), "Taylor Swift");
# Ok(())
# }

Functionality

  • authentication, using OAuth2 (recommended) or BotPasswords
  • error handling, transforming MediaWiki errors into Rust ones (see mwapi_errors)
  • CSRF token handling with post_with_token
  • rate limiting and concurrency controls
  • (planned) file uploads

See also

  • mwbot provides a higher level interface to interacting with MediaWiki
  • mwapi_responses is a macro to generate strict types for dynamic API queries

Contributing

mwapi is a part of the mwbot-rs project. We're always looking for new contributors, please reach out if you're interested!

Dependencies

~5–9MB
~198K SLoC