Crates.io | data-gov |
lib.rs | data-gov |
version | 0.1.1 |
created_at | 2025-09-25 14:14:01.225283+00 |
updated_at | 2025-09-25 18:47:53.90529+00 |
description | Rust client library and CLI for data.gov - search, explore, and download U.S. government datasets |
homepage | https://github.com/dspadea/data-gov-rs |
repository | https://github.com/dspadea/data-gov-rs |
max_upload_size | |
id | 1854677 |
size | 137,795 |
High-level Rust client and CLI for data.gov. It wraps the low-level data-gov-ckan
crate with download helpers, an interactive REPL, and ergonomic configuration.
rustup toolchain install stable
rustup default stable
Use the published crate from crates.io:
[dependencies]
data-gov = "0.1.1"
tokio = { version = "1", features = ["full"] }
Working inside this repository? You can still use a path dependency in Cargo.toml
:
data-gov = { path = "../data-gov" }
Need unreleased features between tags? Swap in the git dependency form instead:
data-gov = { git = "https://github.com/dspadea/data-gov-rs", package = "data-gov" }
git clone https://github.com/dspadea/data-gov-rs.git
cd data-gov-rs/data-gov
cargo install --path .
The data-gov
binary is then available on your PATH.
use data_gov::DataGovClient;
#[tokio::main]
async fn main() -> data_gov::Result<()> {
let client = DataGovClient::new()?;
let results = client.search("climate change", Some(10), None, None, None).await?;
println!("Found {} datasets", results.count.unwrap_or(0));
let dataset = client.get_dataset("consumer-complaint-database").await?;
println!("Dataset: {}", dataset.title.as_deref().unwrap_or(&dataset.name));
let resources = DataGovClient::get_downloadable_resources(&dataset);
if let Some(resource) = resources.first() {
let path = client.download_resource(resource, None).await?;
println!("Downloaded to {path:?}");
}
Ok(())
}
data-gov search "climate change" 5
data-gov show electric-vehicle-population-data
data-gov download electric-vehicle-population-data 0
data-gov list organizations
Key defaults:
data-gov
launches a REPL that stores downloads under ~/Downloads/<dataset>/
./<dataset>/
)--download-dir
, toggle colours with --color
, and silence progress bars via NO_PROGRESS=1
Command | Purpose |
---|---|
search <query> [limit] |
Full-text search with optional result cap |
show <dataset_id> |
Inspect dataset details and resources |
download <dataset_id> [index] |
Download all resources or a specific resource by index |
list organizations |
List publishing organisations |
setdir <path> |
Change the active download directory (REPL only) |
info |
Display current configuration |
help , quit |
Help and exit commands |
The REPL accepts stdin, so shebang scripts work out of the box:
#!/usr/bin/env data-gov
# Simple automation example
search climate 3
download consumer-complaint-database 0
quit
See ../examples/scripting
for ready-made scripts such as download-epa-climate.sh
and list-orgs.sh
.
use data_gov::{DataGovClient, DataGovConfig, OperatingMode};
let config = DataGovConfig::new()
.with_mode(OperatingMode::CommandLine)
.with_download_dir("./data")
.with_api_key("your-api-key")
.with_max_concurrent_downloads(5)
.with_progress(true);
let client = DataGovClient::with_config(config)?;
Configuration covers the underlying CKAN settings, download directory logic, concurrency, progress output, and colour preferences.
cd data-gov-rs
cargo test -p data-gov
cargo run -p data-gov --example demo
The crate re-exports data-gov-ckan
as data_gov::ckan
, making the lower-level client available when you need direct CKAN access.
cargo test
, open a PR⚠️ AI-assisted code: Significant portions of this crate were generated with AI tooling. While the library behaves well in ad-hoc testing, it still needs careful human review and polish before production use.