Pkl or we can say Pickle is the configuration language created by Apple. It is the special-purpose-configuration language. Pkl has built-in features to check for errors and other tools to make your work easier. Pkl treats configuration as code so you can write the configuration, organize it, and keep track of the version like the regular programming language code.
Table of Contents
Use Cases of Pkl Language
Generating Static Configuration
If you are using any tool or application that uses configuration formats like JASON, YAML, or other configuration formats. You can generate the configuration with Pkl to reduce the verbosity and you can increase the maintainability of your configuration by using Pkl features like reuse, templating, and abstraction.
Application runtime configuration
When you are using Pkl as your configuration tool you get a modern and user-friendly system that is safe and easy. Pkl is clearly defined and documented and easier to understand and modify. As your system scales Pkl can handle more complex configuration.
Libraries Maintained by Pkl Language
- pkl-config-java
- pkl-config-kotlin
- pkl-swift
- pkl-go
Concepts of Pkl Language
Abstraction
Configuration gets larger and complex over time making it harder to understand and maintain it. Pkl helps to reduce the size and complexity of configuration by these methods.
- Pkl defines the shared properties of all the elements once instead of repeating them for all the elements and makes the configuration clean and easy to maintain.
- Pkl finds common patterns or similarities in elements and makes a general template or module of those similarities and you can use the template wherever you need.
- To make the system more flexible it separates the blueprint of the configuration and the data of the configuration.
- Instead of manually defining each configuration, it uses code or logic to generate the configuration based on the rules and the parameters.
Evaluation
Pkl organizes its code in modules or you can say in files. When you run a Pkl module, it processes the code to create an in-memory data model. This data model displays the configuration just like the JSON, which is the most used configuration structure.
If the evaluation is successful with no errors, the data model is converted to an external representation like a JSON or YAML file. The evaluation finishes successfully with a status 0 code.
If there are errors in the evaluation, then it will show the error message and it ends with a non-zero status code.
Immutability
In Pkl, any data you create, cannot be changed. If you want to modify a value, the system will create a new value, and the original value stays the same. It makes the program easier to debug and the risk of getting potential errors is low because with immutability original values are consistent and never changed so there’s no risk of unintentionally modifying the values.
Isolation
Pkl ensures safety and security when running its code using the sandboxing technique. If there are bugs in the code, it won’t affect anything outside the sandbox. Even if there is malicious code in Pkl the worst it can do is consume memory and CPU.
Usability
Pkl is designed to be user-friendly and easy to use, especially for people who use it occasionally. If there is an error occurs Pkl explains what causes the error and how to fix it. It helps users to fix errors quickly. To avoid unexpected behavior, it makes configuration easier to understand and ensures the order of properties in objects remains the same.
Templating
Pkl allows you to create reusable templates to simplify complex tasks. Instead of writing the complete configurations every time, you just create a template and can use it in your code to fill the blank of the properties that are already defined in the template. Templates can be shared across the network that allows teams and communities to collaborate.
Reusing
Pkl allows inclusion of configurations of other modules by importing them into the module and these modules can be located locally and remotely. Instead of writing one bigger configuration file, you can break it into smaller modules and then you can import them into the main module. Pkl ensures security when using module imports.
Schema
Pkl allows you to define a configuration schema to structure. while using a schema is optional, it offers significant advantages for handling complex configurations.
Rendering
Rendering is the process of converting a structured data model into an external representation. Pkl supports these data formats:
- JSON
- Jsonnet
- Pcf (a static subset of Pkl)
- (Java) Properties
- Property List
- XML
- YAML
Resemblance
Pkl code is visually similar to the code you write. It makes the code easy to write and understand.
You can access the official Pkl Language official website through this link.