20 releases (9 stable)

5.7.0 Jan 6, 2024
5.6.0 Oct 29, 2023
5.5.1 Jul 31, 2023
5.5.0 Jan 20, 2023
0.2.0 Sep 15, 2020

#684 in Database interfaces

Download history 50/week @ 2024-01-03 3/week @ 2024-01-17 10/week @ 2024-01-24 2/week @ 2024-02-14 17/week @ 2024-02-21 29/week @ 2024-02-28 2/week @ 2024-03-06 16/week @ 2024-03-13 7/week @ 2024-03-27 47/week @ 2024-04-03

71 downloads per month


583 lines


crates.io docs.rs pipeline status

The toolforge crate provides helper functions for various tasks on Toolforge.

See wikitech for the full documentation.


toolforge is (C) 2013, 2017, 2020-2021 Kunal Mehta, released under the GPL v3 or any later version, see COPYING for details.


The toolforge crate provides helper functions for various tasks on Toolforge.

Constructing a User-Agent

The user_agent! macro generates a tool-specific User-Agent header in compliance with Wikimedia's User-Agent policy. The first and only required parameter is the tool's name. Optional second and third parameters can be overrides to the url and email, respectively.


const USER_AGENT: &str = toolforge::user_agent!("mycooltool");

    "https://mycooltool.toolforge.org/ tools.mycooltool@toolforge.org"

WikiReplica connection helpers

The connection_info! macro builds the URL string to connect to Wiki Replicas for use with the mysql_async crate. It should also work with the mysql crate. Specifically, it follows the Toolforge connection handling policy.

The first argument is the database name, with or without a _p suffix. The second (optional) argument is which cluster to connect to, either WEB (default) or ANALYTICS.


use mysql_async::Pool;
let pool = Pool::new(
    toolforge::connection_info!("enwiki", WEB)
        .expect("unable to load db config")
let mut conn = pool.get_conn().await?;

Local development

Copy your tool's replica.my.cnf to your local machine, saving it to ~/replica.my.cnf and add a local='true' flag. For example:


Then open a SSH tunnel on port 3306 to the specific wiki replicas database you want to access. The toolforge-tunnel helper described below can simplify this.

WikiPool feature

WikiPool is a wrapper around mysql_async::Pool that given a database name, will connect to the appropriate backend server. It is smart enough to know which databases are on the same server so connections can be optimally reused for better performance. This is behind the wikipool feature.

toolforge-tunnel helper

The toolforge-tunnel tool simplifies the process of opening SSH tunnels to wiki replicas. Example usage: toolforge-tunnel enwiki.

It can be installed via cargo: cargo install toolforge --features=cli. Pre-built binaries can be downloaded from GitLab.


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


~135K SLoC