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.
先审查再安装
这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。
npx -y tokrepo@latest install 8e845296-3997-11f1-9bc6-00163e2b0d79 --target codex先 dry-run,确认写入项后再运行此命令。
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.
常见问题
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.
引用来源 (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
讨论
相关资产
CUE — Validate, Define, and Generate Configuration with Types
CUE is a data constraint language that unifies schema definition, validation, and code generation for JSON, YAML, Protobuf, and more, replacing scattered scripts with a single type-safe configuration layer.
Jsonnet — Data Templating Language for Configuration
Jsonnet is a data templating language from Google that extends JSON with variables, conditionals, functions, and imports to generate complex configuration files for Kubernetes, Terraform, and other systems.
Dagger — CI/CD Pipelines as Code in Any Language
Run CI/CD pipelines locally and in the cloud with the same code. Write pipelines in TypeScript, Python, or Go instead of YAML. Containerized execution ensures identical results everywhere. 12,000+ stars.
Chef Infra — Configuration Management and Infrastructure Automation
A configuration management platform that automates how infrastructure is configured, deployed, and managed. Uses a Ruby-based DSL to define system state as code, ensuring consistency across thousands of nodes.