24 releases

0.7.0-rc.1 Jun 2, 2024
0.6.0 Dec 15, 2023
0.5.0 Apr 3, 2023
0.5.0-alpha.3 Feb 20, 2023
0.2.2 Jun 22, 2021

#505 in Web programming

Download history 165/week @ 2024-06-15 115/week @ 2024-06-22 146/week @ 2024-06-29 119/week @ 2024-07-06 94/week @ 2024-07-13 99/week @ 2024-07-20 129/week @ 2024-07-27 100/week @ 2024-08-03 88/week @ 2024-08-10 97/week @ 2024-08-17 166/week @ 2024-08-24 78/week @ 2024-08-31 48/week @ 2024-09-07 50/week @ 2024-09-14 89/week @ 2024-09-21 76/week @ 2024-09-28

271 downloads per month
Used in 2 crates

GPL-3.0-or-later

61KB
1K SLoC

mwapi

crates.io docs.rs docs (main) pipeline status coverage report

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!

License

This crate is released under GPL-3.0-or-later. See COPYING for details.

Dependencies

~6–18MB
~247K SLoC