Pkl is a configuration language from Apple that catches errors before deployment. Type-safe, programmable configs that generate YAML, JSON, or any format.
Basic Syntax
// config.pkl
name = "my-app"
port = 8080
debug = false
database {
host = "localhost"
port = 5432
name = "mydb"
maxConnections = 20
}
features {
enableNewUI = true
maxUploadSizeMB = 50
}
Type Safety
// AppConfig.pkl — define your schema
class DatabaseConfig {
host: String
port: UInt16 // Must be 0-65535
name: String
maxConnections: Int(isBetween(1, 100)) // Validated!
}
class AppConfig {
name: String
port: UInt16
debug: Boolean
database: DatabaseConfig
}
// If someone sets maxConnections = 200, Pkl catches it at generation time
Generate YAML/JSON
# Generate YAML
pkl eval config.pkl -f yaml
# Output:
# name: my-app
# port: 8080
# database:
# host: localhost
# port: 5432
# Generate JSON
pkl eval config.pkl -f json
# Generate for Kubernetes
pkl eval k8s-deployment.pkl -f yaml > deployment.yaml
Programmable Configs
// environments.pkl
local baseConfig: AppConfig = new {
name = "my-app"
database {
maxConnections = 20
}
}
dev: AppConfig = (baseConfig) {
port = 3000
debug = true
database {
host = "localhost"
}
}
prod: AppConfig = (baseConfig) {
port = 8080
debug = false
database {
host = "db.production.internal"
maxConnections = 100
}
}
Kubernetes Example
// k8s.pkl
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.0#/api/apps/v1/Deployment.pkl"
output {
renderer = new YamlRenderer {}
value = new Deployment {
metadata {
name = "my-app"
namespace = "production"
}
spec {
replicas = 3
template {
spec {
containers {
new {
name = "app"
image = "my-app:latest"
ports { new { containerPort = 8080 } }
}
}
}
}
}
}
}
Why This Matters
- Type-safe: Catch config errors before deployment
- IDE support: Autocomplete, hover docs, error highlighting
- Multi-format: Generate YAML, JSON, Property Lists
- From Apple: Battle-tested in Apple's internal infrastructure
Need custom configuration tools or DevOps automation? I build developer tools. Check out my web scraping actors on Apify or reach out at spinov001@gmail.com for custom solutions.
Top comments (0)