Skills2026年4月16日·1 分钟阅读

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 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Pkl Overview
先审查命令
npx -y tokrepo@latest install 8e845296-3997-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
Pkl replaces YAML and JSON configuration sprawl with a typed, programmable configuration language by Apple.
§01

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.

§02

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.

§03

How to use

  1. 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/
  1. 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'
}
  1. Evaluate to YAML or JSON:
pkl eval config.pkl -f yaml
pkl eval config.pkl -f json
§04

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.

§05

Related on TokRepo

§06

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 eval step.

常见问题

Can Pkl generate Kubernetes manifests?+

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.

How does Pkl compare to CUE or Dhall?+

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.

Does Pkl have IDE support?+

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.

Can I use Pkl with existing YAML workflows?+

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.

Is Pkl open source?+

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)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产