Introduction
Pkl is a configuration language created by Apple that brings programming constructs — classes, functions, type checking, and validation — to the world of configuration files. It catches errors before deployment instead of at runtime, replacing fragile YAML and JSON with a structured, IDE-friendly format that scales to large codebases.
What Pkl Does
- Defines strongly typed configuration with classes, inheritance, and constraints
- Validates configuration values at evaluation time with built-in assertions
- Generates output in JSON, YAML, Property Lists, and other formats
- Provides first-class IDE support with IntelliJ and VS Code extensions
- Supports modular imports and package management for reusable config libraries
Architecture Overview
Pkl programs are evaluated by the Pkl evaluator, which parses .pkl files into an AST, performs type checking and constraint validation, and then renders the output into the target format. The evaluator is written in Kotlin and runs on the JVM, but native binaries are available for macOS, Linux, and Windows. Pkl also provides language bindings for Go, Java, Kotlin, and Swift to embed evaluation into applications.
Self-Hosting & Configuration
- Install the standalone CLI binary or use the Gradle/Maven plugin for JVM projects
- Define project dependencies in
PklProjectfiles with versioned remote packages - Use
pkl-gen-goorpkl-gen-javato generate typed data classes from Pkl schemas - Configure output format with
--format json,--format yaml, or--format plist - Enable watch mode with
pkl eval --watchfor live feedback during development
Key Features
- Rich type system with generics, union types, and nullable types
- Constraint expressions like
age >= 0 && age <= 150validated at eval time - Amends pattern for layered configuration (base, staging, production)
- Package manager for sharing and versioning configuration modules
- Native binaries eliminate JVM startup time for CLI usage
Comparison with Similar Tools
- CUE — similar validation focus but steeper learning curve and smaller ecosystem
- Jsonnet — functional JSON templating but lacks type checking and IDE support
- Dhall — typed config language but limited output formats and slower adoption
- HCL (Terraform) — domain-specific for infrastructure, not a general config language
- YAML + JSON Schema — standard but no programming constructs or module system
FAQ
Q: Does Pkl replace YAML in Kubernetes manifests? A: Pkl can generate YAML for Kubernetes. Apple provides a k8s package for typed Kubernetes resource definitions.
Q: Is the JVM required to run Pkl? A: No, native binaries are available for macOS, Linux, and Windows that do not require a JVM.
Q: Can I use Pkl with existing JSON/YAML configs? A: Yes, Pkl can read JSON and YAML as input and convert them into typed Pkl modules.
Q: What languages have Pkl code generation support? A: Go, Java, Kotlin, and Swift have official code generation tools that produce typed data classes from Pkl schemas.