#dump #io #download #crates-io #time-series #scripting #tar

db-dump

Library for scripting analyses against crates.io's database dumps

41 releases

new 0.7.9 Dec 4, 2024
0.7.8 Nov 30, 2024
0.7.5 Oct 29, 2024
0.7.4 Jul 5, 2024
0.1.0 Mar 16, 2021

#98 in Database interfaces

Download history 137/week @ 2024-08-18 183/week @ 2024-08-25 166/week @ 2024-09-01 154/week @ 2024-09-08 129/week @ 2024-09-15 197/week @ 2024-09-22 155/week @ 2024-09-29 178/week @ 2024-10-06 153/week @ 2024-10-13 174/week @ 2024-10-20 336/week @ 2024-10-27 283/week @ 2024-11-03 278/week @ 2024-11-10 467/week @ 2024-11-17 370/week @ 2024-11-24 525/week @ 2024-12-01

1,668 downloads per month
Used in 2 crates

MIT/Apache

200KB
2K SLoC

crates.io database dumps

github crates.io docs.rs build status

Library for scripting analyses against crates.io's database dumps.

These database dumps contain all information exposed by the crates.io API packaged into a single download. An updated dump is published every 24 hours. The latest dump is available at https://static.crates.io/db-dump.tar.gz.


Examples

The examples/ directory of this repo contains several runnable example analyses.

total‑downloads Computes time series of total downloads by day across all crates on crates.io
crate‑downloads Computes time series of downloads of one specific crate
top‑crates Computes the top few most directly depended upon crates
user‑dependencies Computes the percentage of crates.io which depends directly on at least one crate by the specified user
user‑downloads Computes time series of the fraction of crates.io downloads attributed to a single given user's crates

Each of these examples can be run using Cargo once you've downloaded a recent database dump:

$ wget https://static.crates.io/db-dump.tar.gz
$ cargo run --release --example total-downloads

Here is the implementation of the most basic example, total-downloads, and graph of the resulting table. It shows crates.io download rate doubling every 9 months, or equivalently 10× every 2.5 years!

use chrono::Utc;
use db_dump::Date;
use std::collections::BTreeMap as Map;

fn main() -> db_dump::Result<()> {
    let mut downloads = Map::<Date<Utc>, u64>::new();
    db_dump::Loader::new()
        .version_downloads(|row| {
            *downloads.entry(row.date).or_default() += row.downloads;
        })
        .load("./db-dump.tar.gz")?;

    for (date, count) in downloads {
        println!("{},{}", date, count);
    }

    Ok(())
}
Crates.io downloads per day (log scale)

Here is a graph from the user-downloads example:

Fraction of crates.io downloads that are dtolnay's crates

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~8–17MB
~235K SLoC