Pkl — Configuration as Code Language by Apple
Pkl is a programmable configuration language with rich validation, templating, and IDE support, designed to replace YAML and JSON sprawl.
What it is
Pkl is a programmable configuration language developed by Apple. It provides typed schemas, validation constraints, templating, and IDE support for configuration files. Instead of writing raw YAML or JSON with no validation until runtime, you define configuration as Pkl code with types, defaults, and constraints that are checked at evaluation time.
Pkl is designed for platform engineers, DevOps teams, and application developers who manage complex configuration across multiple environments and want compile-time safety.
How it saves time or tokens
YAML and JSON configuration files are error-prone: a mistyped key, a wrong type, or a missing field causes runtime failures. Pkl catches these errors at evaluation time before deployment. The language supports modules, imports, and inheritance, so you can define a base configuration once and override per environment. This eliminates copy-paste duplication across dev/staging/production configs and reduces configuration-related incidents.
How to use
- Install the Pkl CLI:
curl -L https://github.com/apple/pkl/releases/latest/download/pkl-linux-amd64 -o pkl
chmod +x pkl && sudo mv pkl /usr/local/bin/
- Create a Pkl configuration file:
// config.pkl
module Config
name: String = 'my-app'
port: Int(this >= 1024 && this <= 65535) = 8080
debug: Boolean = false
database {
host: String = 'localhost'
port: Int = 5432
name: String = 'mydb'
}
- Evaluate to YAML or JSON:
pkl eval config.pkl -f yaml
pkl eval config.pkl -f json
Example
Environment-specific configuration with inheritance:
// base.pkl
module BaseConfig
name: String
replicas: Int = 1
resources {
cpu: String = '100m'
memory: String = '256Mi'
}
// production.pkl
amends "base.pkl"
name = 'api-server'
replicas = 3
resources {
cpu = '500m'
memory = '1Gi'
}
pkl eval production.pkl -f yaml outputs the merged configuration with production overrides applied.
Related on TokRepo
- DevOps tools — Browse infrastructure and configuration tools
- Automation tools — Explore configuration management automation
Common pitfalls
- Trying to use Pkl as a general-purpose programming language. Pkl is designed for configuration, not application logic. It has deliberate limitations (no loops with side effects, no I/O) to keep configurations deterministic.
- Not leveraging the type system. Writing Pkl without type annotations and constraints misses the main benefit. Add types and validation constraints to catch errors before deployment.
- Forgetting that Pkl evaluates to a data format (YAML, JSON, plist). Your tooling consumes the output, not Pkl files directly. Ensure your CI pipeline includes a
pkl evalstep.
Frequently Asked Questions
Yes. Pkl can generate YAML for Kubernetes manifests. Apple provides a Kubernetes module (pkl-k8s) with typed schemas for all Kubernetes API objects, giving you type-safe Kubernetes configuration.
All three are typed configuration languages. Pkl emphasizes readability and IDE support with a familiar syntax. CUE focuses on data validation and unification. Dhall provides a dependently-typed functional approach. Pkl is backed by Apple and has strong IDE integration.
Yes. Pkl provides plugins for IntelliJ, VS Code, and Neovim with syntax highlighting, autocompletion, inline validation, and go-to-definition. The language server protocol (LSP) implementation powers these features.
Yes. Pkl evaluates to YAML, JSON, or plist output. You write configuration in Pkl, generate YAML/JSON, and your existing tools consume the output. This means you can adopt Pkl incrementally without changing downstream tooling.
Yes. Pkl is open source under the Apache 2.0 license. Apple released it publicly with the CLI, language server, and standard library all available on GitHub.
Citations (3)
- Pkl GitHub— Pkl is a configuration language by Apple
- Pkl Documentation— Pkl language documentation and examples
- pkl-k8s— Pkl Kubernetes module for typed K8s configs
Related on TokRepo
Discussion
Related Assets
doctest — The Fastest Feature-Rich C++ Testing Framework
doctest is a single-header C++ testing framework designed for minimal compile-time overhead and maximum speed.
Chai — BDD/TDD Assertion Library for Node.js
Chai is a flexible assertion library for Node.js and browsers that supports expect, should, and assert styles.
Supertest — HTTP Assertion Library for Node.js APIs
Supertest provides a high-level API for testing HTTP servers in Node.js with fluent assertion chaining.