Pkl is a config managment language developed by Apple. It is a simple language to manage configuration files. It has plugin support for popular editors and support for golang.

Sample project

Let’s start with a simple go project.

go mod init pkl-sample
touch main.go
package main

import (

func main() {
    fmt.Println("Hello, World!")

Install pkl

First, let’s install pkl using brew.

brew install pkl

Then, Let’s install pkl-go library in our project.

go get

Let’s also install codegen tool for pkl.

go install

Create a pkl config

Let’s create a pkl file pkl/AppConfig.pkl

@go.Package { name = "pkl-sample/appconfig" }
module pkl-sample.AppConfig

import "package://"

greeting: String = "Hello, "
message: String = "World!"

note the target package name pkl-sample/appconfig in the @go.Package annotation.

it will be used to generate the go code.

Generate Go code

pkl-gen-go pkl/AppConfig.pkl --base-path pkl-sample

This will generate go files appconfig/AppConfig.go and appconfig/init.pkl.go

Use the generated code

package main

import (

func main() {
    cfg, err := appconfig.LoadFromPath(context.Background(), "pkl/AppConfig.pkl")
	if err != nil {
    fmt.Println(cfg.Greeting + cfg.Message)


Although it’s a bit workaround to setup pkl, the flexibility it offers is good and it’s a good standard to follow for configuration management in any project.

It can also convert config to other formats like json, yaml, etc.

on top of it, we can use the same .pkl file to generate code for other languages like swift, kotlin, etc.