23 releases

0.6.0 Dec 15, 2023
0.5.0 Apr 3, 2023
0.5.0-alpha.3 Feb 20, 2023
0.4.3 Dec 1, 2022
0.2.2 Jun 22, 2021

#1214 in Web programming

Download history 19/week @ 2023-12-03 67/week @ 2023-12-10 50/week @ 2023-12-24 60/week @ 2023-12-31 23/week @ 2024-01-07 1/week @ 2024-01-14 28/week @ 2024-01-21 35/week @ 2024-01-28 48/week @ 2024-02-11 20/week @ 2024-02-18 54/week @ 2024-02-25 4/week @ 2024-03-03 8/week @ 2024-03-10 6/week @ 2024-03-17

74 downloads per month
Used in 2 crates

GPL-3.0-or-later

56KB
1K SLoC

mwapi

crates.io docs.rs pipeline status coverage report

See the full documentation (docs for main).

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

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");

Functionality

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

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

~6–21MB
~303K SLoC