arch-pkg-db

Crates.ioarch-pkg-db
lib.rsarch-pkg-db
version0.0.0
created_at2025-11-16 11:42:39.454859+00
updated_at2025-11-16 11:42:39.454859+00
descriptionPure Rust library to read Arch Linux's package database archives
homepage
repositoryhttps://github.com/pacman-repo-builder/arch-pkg-db.git
max_upload_size
id1935418
size159,125
Khải (KSXGitHub)

documentation

README

arch-pkg-db

Pure Rust library to read Arch Linux's package database archives. "Pure Rust" means not needing libalpm.

Description

This is a collection of APIs that allow for loading a database of pacman packages and query them.

The database could be a local database of installed packages or a sync database of all installable packages.

The sync database may or may not contain non-official repositories, with duplicated package names.

Why not libalpm?

Relying on libalpm has 2 limitations:

  • The program would only work on Arch Linux.
  • Every time libalpm updates, the program would need to be recompiled. And since Arch Linux is rolling release, libalpm would update frequently, forcing the program to recompile frequently.

This library aims to provide the means to query pacman packages without the above limitations.

Documentation

See docs.rs.

Quick Start

Querying installed packages

use arch_pkg_db::{TextCollection, EagerQueryDatabase, desc::Query, value::Name};

let texts = TextCollection::par_from_local_db("/var/lib/pacman/local/".as_ref()).unwrap();
let db: EagerQueryDatabase = texts.par_parse().unwrap();

let pkg = db.get(Name("bash")).unwrap();
println!("Name: {}", pkg.name().unwrap());
println!("Version: {}", pkg.version().unwrap());
println!("Description: {}", pkg.description().unwrap());

Querying installable packages without caring about repository names

use std::fs::read;
use arch_pkg_db::{TextCollection, EagerQueryDatabase, desc::Query, value::Name};

let texts = TextCollection::new()
    .add_archive(&read("/var/lib/pacman/sync/core.db").unwrap())
    .unwrap()
    .add_archive(&read("/var/lib/pacman/sync/extra.db").unwrap())
    .unwrap()
    .add_archive(&read("/var/lib/pacman/sync/multilib.db").unwrap())
    .unwrap();

let db: EagerQueryDatabase = texts.par_parse().unwrap();

let pkg = db.get(Name("bash")).unwrap();
println!("Name: {}", pkg.name().unwrap());
println!("Version: {}", pkg.version().unwrap());
println!("Description: {}", pkg.description().unwrap());

Querying installable packages and their repository names

use std::fs::read;
use arch_pkg_db::{
    MultiTextCollection,
    EagerMultiQueryDatabase,
    desc::Query,
    value::{Name, RepositoryName},
};

let multi_texts = MultiTextCollection::new()
    .add_archive(RepositoryName("core"), &read("/var/lib/pacman/sync/core.db").unwrap())
    .unwrap()
    .add_archive(RepositoryName("extra"), &read("/var/lib/pacman/sync/extra.db").unwrap())
    .unwrap()
    .add_archive(RepositoryName("multilib"), &read("/var/lib/pacman/sync/multilib.db").unwrap())
    .unwrap()
    .add_archive(RepositoryName("chaotic-aur"), &read("/var/lib/pacman/sync/chaotic-aur.db").unwrap())
    .unwrap()
    .add_archive(RepositoryName("arch-derivative-distro"), &read("/var/lib/pacman/sync/arch-derivative-distro.db").unwrap())
    .unwrap()
    .add_archive(RepositoryName("my-personal-repo"), &read("/var/lib/pacman/sync/my-personal-repo.db").unwrap())
    .unwrap();

let db: EagerMultiQueryDatabase = multi_texts.par_parse().unwrap();

let Some(pkgs) = db.get(Name("paru")) else {
    println!("No repositories contain paru");
    return;
};

for (repository, pkg) in pkgs.entries() {
    let name = pkg.name().unwrap();
    let version = pkg.version().unwrap();
    println!("{repository}/{name} {version}");
}

More examples

See the examples directory.

License

MIT © Hoàng Văn Khải.

Commit count: 0

cargo fmt