22 releases

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

#1143 in Web programming

Download history 103/week @ 2023-02-18 135/week @ 2023-02-25 128/week @ 2023-03-04 122/week @ 2023-03-11 157/week @ 2023-03-18 86/week @ 2023-03-25 109/week @ 2023-04-01 98/week @ 2023-04-08 196/week @ 2023-04-15 90/week @ 2023-04-22 238/week @ 2023-04-29 225/week @ 2023-05-06 130/week @ 2023-05-13 100/week @ 2023-05-20 130/week @ 2023-05-27 92/week @ 2023-06-03

481 downloads per month
Used in mwbot

GPL-3.0-or-later

85KB
1.5K 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

# #[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
  • 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

~7–15MB
~303K SLoC