| Crates.io | wbi-rs |
| lib.rs | wbi-rs |
| version | 0.1.8 |
| created_at | 2025-08-20 16:35:05.143025+00 |
| updated_at | 2025-08-29 07:45:57.820037+00 |
| description | A Rust library + CLI to fetch, store, visualize, and summarize World Bank indicator data. |
| homepage | https://crates.io/crates/wbi-rs |
| repository | https://github.com/ArdentEmpiricist/world_bank_data_rust |
| max_upload_size | |
| id | 1803683 |
| size | 3,315,097 |
Fetch, analyze, and visualize World Bank data from Rust.
This project provides a CLI, GUI, and library API to retrieve time series from the World Bank API, export them safely (CSV/JSON), compute grouped statistics, and render charts (SVG/PNG) with Plotters.
Status: actively developed. Library API is stable enough for use; updates follow semantic versioning.
source; the client transparently fans out per indicator when --source is omitted, while still supporting the single-call path when --source is provided.--out extension or set via --format).--plot file extension).--country-styles, series from the same country share consistent base colors while indicators are differentiated by shades and patterns.User-Agent: wbi_rs).NaN/±∞ → null).Download a prebuilt binary (GitHub Releases):
Via cargo/crates.io:
# Install both CLI and GUI binaries (default)
cargo install wbi-rs
wbi --help # CLI binary
wbi-gui # GUI binary
# Install CLI only
cargo install wbi-rs --bin wbi
wbi --help
# Install GUI only
cargo install wbi-rs --bin wbi-gui
wbi-gui
From source:
git clone <this-repo>
cd wbi-rs
# Build both CLI and GUI binaries (default)
cargo build --release
# Build CLI only
cargo build --release --bin wbi
# Build GUI only
cargo build --release --bin wbi-gui
As a library (example):
[dependencies]
wbi-rs = "0.1" # or your path
anyhow = "1"
Fetch population for Germany & France (2000–2023), write to CSV (format inferred from extension) and show quick stats in terminal:
wbi get \
--countries DEU,FRA \
--indicators SP.POP.TOTL \
--date 2000:2023 \
--out pop.csv \
--stats
Output:
Fetch GDP (in current US$) for the US, China, Germany and India and render a plot (backend inferred from extension):
wbi get \
--countries USA,CHN,DEU,IND \
--indicators NY.GDP.MKTP.CD \
--date 1970:2025 \
--plot pop.svg \
--plot-kind line-points
Output:
You can enable country-consistent styling where all series for the same country share one base hue from the MS Office palette, while indicators within that country are differentiated by shades:
# Use country-consistent styling
wbi get \
--countries USA,CHN,IND,DEU \
--indicators SP.POP.TOTL,SP.POP.TOTL.FE.IN \
--date 2010:2020 \
--plot multi_indicator.svg \
--plot-kind line-points \
--country-styles
This feature ensures that:
Output:
For users who prefer a graphical interface, wbi-rs includes a modern, cross-platform desktop application.
Build and run the GUI:
cargo build --release --bin wbi-gui
cargo run --release --bin wbi-gui
The GUI provides an intuitive interface for:
Advanced options for plots only visible if "Create chart" checkbox is active.
The GUI application works on:
USA,DEU,CHNSP.POP.TOTL,NY.GDP.MKTP.CDThe application will download the data, save it to your chosen location, and create a chart—all with a single click.
Subcommand get accepts at least:
--countries ISO2/ISO3 codes separated by , or ; (e.g., DEU,FRA or (attention: " " are required using ;) "DEU;FRA")--indicators World Bank indicator IDs (e.g., SP.POP.TOTL)--date optional year or range (e.g., 2020 or 2000:2023)--source optional source ID (e.g., 2 for WDI). Recommended for efficiency when querying multiple indicators, but optional.--out <PATH> optional export (CSV/JSON); atomic--plot <PATH> optional chart output (SVG/PNG), using Plotters--country-styles enable country-consistent styling with optional mode (on|symbols|off)--out--format is not provided, the format is inferred:
.csv → CSV.json → JSON--format) → error--format is provided:
--out data.csv --format json) error early# CSV via extension inference
wbi get --countries DEU --indicators SP.POP.TOTL --out data.csv
# JSON via extension inference
wbi get --countries DEU --indicators SP.POP.TOTL --out data.json
# Unknown extension allowed when --format is explicit
wbi get --countries DEU --indicators SP.POP.TOTL --out dump.xyz --format csv
# Error on conflict
wbi get --countries DEU --indicators SP.POP.TOTL --out data.csv --format json
The crate exposes modules for API access, models, storage, statistics, and plotting.
Cargo.toml[dependencies]
wbi-rs = "0.1" # or "{ path = "." } to your source"
anyhow = "1"
use anyhow::Result;
use wbi_rs::api::Client;
use wbi_rs::models::DateSpec;
fn main() -> Result<()> {
// Hardened blocking client (rustls, timeouts, redirect policy, UA)
let api = Client::default();
// Countries & indicators can be given as lists; date is optional
let points = api.fetch(
&["DEU".into(), "FRA".into()],
&["SP.POP.TOTL".into()],
Some(DateSpec::Range { start: 2000, end: 2023 }),
None, // source id
)?;
println!("rows: {}", points.len());
Ok(())
}
For multi-indicator requests when source is None, the client automatically handles fallback behavior by making separate requests per indicator to ensure data retrieval succeeds.
The fetch method automatically enriches DataPoint.unit values when observation rows lack a unit by fetching metadata from the World Bank indicator endpoint. This ensures that visualization and analysis code has access to appropriate unit information for axis labeling and scaling decisions.
If you need to manually fetch indicator units for specific indicators:
let units = api.fetch_indicator_units(&["SP.POP.TOTL".into(), "NY.GDP.MKTP.CD".into()])?;
// Returns HashMap<String, String> mapping indicator ID to unit
use wbi_rs::storage::{save_csv, save_json};
save_csv(&points, "pop.csv")?; // spreadsheet-safe + atomic
save_json(&points, "pop.json")?; // non-finite -> null + atomic
=, +, -, @ are prefixed with '.null.Both writers use a tempfile in the destination directory and atomically replace the target file.
use wbi_rs::stats::{grouped_summary, Summary};
let summaries: Vec<Summary> = grouped_summary(&points);
// Summary contains: key (indicator_id, country_iso3), count, missing, min, max, mean, median.
// Non-finite values are counted as missing; sorting avoids panics on floats.
use wbi_rs::viz::plot_chart;
// `plot_chart` filters non-finite values and sorts by integer year.
// The backend is selected from the output extension (.svg, .png).
plot_chart(&points, "pop.svg")?;
Charts automatically derive appropriate units for axis labeling using a two-tier approach:
This approach ensures that both API-provided units and legacy indicator naming conventions are properly handled for visualization.
// Simplified view
pub struct DataPoint {
pub indicator_id: String,
pub indicator_name: String,
pub country_id: String,
pub country_name: String,
pub country_iso3: String,
pub year: i32,
pub value: Option<f64>, // may be None for missing
pub unit: Option<String>,
pub obs_status: Option<String>,
pub decimal: Option<i64>,
}
indicator_id, indicator_name, country_id, country_name, country_iso3, year, value, unit, obs_status, decimalcsv crate (RFC-4180)None → empty cell=, +, -, @ are prefixed with ' (prevents formula execution)nullrustlsUser-AgentRun all tests:
# use without --feature online to test local only
cargo test --features online
Coverage includes:
')cmd_get (inference, explicit flags, conflicts)Contributions are welcome! Please follow these guidelines:
Discuss major changes first: open an issue to align on scope/design before large features or public API changes.
Keep PRs focused: small, single-purpose PRs are easier to review and merge.
Code quality: ensure all of the following pass locally or supply arguments why some parts do not pass:
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all -- --nocapture
Commit messages: using Conventional Commits is appreciated (e.g., feat:, fix:, docs:).
License: by contributing, you agree your changes are dual MIT and Apache-2.-licensed.
Licensed under either of
at your option.
Any contribution intentionally submitted for inclusion in this work shall be dual licensed as above, without any additional terms or conditions.
This project is an independent, community-maintained library and CLI. It is not affiliated with, endorsed by, or sponsored by The World Bank Group or any of its institutions. “The World Bank” name and any related trademarks are the property of The World Bank Group and are used here solely for identification purposes.
This software accesses publicly available data via the World Bank Indicators API. Your use of any World Bank data is governed by the World Bank’s terms and applicable data licenses. No warranty is provided; use at your own risk.