https://github.com/pacman-repo-builder/arch-pkg-db
Pure Rust library to read Arch Linux's package database archives
https://github.com/pacman-repo-builder/arch-pkg-db
archlinux database no-libalpm pacman pure-rust
Last synced: 4 months ago
JSON representation
Pure Rust library to read Arch Linux's package database archives
- Host: GitHub
- URL: https://github.com/pacman-repo-builder/arch-pkg-db
- Owner: pacman-repo-builder
- License: mit
- Created: 2025-02-09T08:55:49.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-11-24T10:53:07.000Z (8 months ago)
- Last Synced: 2025-12-13T15:36:18.039Z (7 months ago)
- Topics: archlinux, database, no-libalpm, pacman, pure-rust
- Language: Rust
- Homepage: https://crates.io/crates/arch-pkg-db
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
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](https://docs.rs/arch-pkg-db/).
## Quick Start
### Querying installed packages
```rust no_run
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
```rust no_run
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
```rust no_run
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](https://github.com/pacman-repo-builder/arch-pkg-db/tree/master/examples) directory.
## License
[MIT](https://github.com/pacman-repo-builder/arch-pkg-db/blob/master/LICENSE.md) © [Hoàng Văn Khải](https://github.com/KSXGitHub).