#configuration-language #codegen #pkl #apple

rpkl

Bindings and codegen for Apple's Pkl configuration language

15 unstable releases (5 breaking)

Uses new Rust 2024

0.6.0 Jul 27, 2025
0.5.0 Jun 14, 2025
0.4.1 Feb 17, 2025
0.3.5 Nov 13, 2024
0.3.0 Jul 23, 2024

#286 in Database interfaces

Download history 494/week @ 2025-07-15 1253/week @ 2025-07-22 320/week @ 2025-07-29 308/week @ 2025-08-05 412/week @ 2025-08-12 514/week @ 2025-08-19 591/week @ 2025-08-26 680/week @ 2025-09-02 334/week @ 2025-09-09 958/week @ 2025-09-16 988/week @ 2025-09-23 821/week @ 2025-09-30 617/week @ 2025-10-07 567/week @ 2025-10-14 399/week @ 2025-10-21 237/week @ 2025-10-28

2,054 downloads per month
Used in 13 crates (4 directly)

MIT license

165KB
4K SLoC

rpkl

crates.io docs.rs build status

Language bindings to Pkl for Rust.

Requires the pkl binary to be available on your path. You can install pkl for your os using the steps from their docs: https://pkl-lang.org/main/current/pkl-cli/index.html#installation

Usage

ip = "127.0.0.1"

database {
    username = "admin"
    password = "secret"
}
#[derive(Deserialize)]
struct Config {
    ip: String,
    database: Database,
}

#[derive(Deserialize)]
struct Database {
    username: String,
    password: String,
}

let config: Config = rpkl::from_config("./config.pkl")?;

Evaluator Options

You can pass options to the evaluator, such as properties, by using from_config_with_options.

username = read("prop:username")
password = read("prop:password")
let options = EvaluatorOptions::default()
.properties([("username", "root"), ("password", "password123")]);

let config: Config = rpkl::from_config_with_options("./config.pkl", Some(options))?;

Codegen

Codegen can be enabled by adding the codegen feature.

use rpkl::{api::Evaluator, codegen::CodegenOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut evaluator = Evaluator::new()?;
    let pkl_mod = evaluator.evaluate_module("example.pkl")?;
    let code: String = pkl_mod.codegen()?;
    std::fs::write("src/example.rs", code)?;
    Ok(())
}

You can also generate code using the experimental CLI.

For more info on codegen, see the docs.

Dependencies

~0.8–2.2MB
~42K SLoC