Skip to main content
Version: 0.7


The KCL Format tool supports reformatting KCL files to the standard code style. This article demonstrates the KCL code style and how to use the KCL Format tool.

Code Style

The KCL Format tool modifies the files according to the KCL code style: Style Guide for KCL Code

How to use

  • Formatting Single File
kcl fmt your_config.k
  • Formatting multiple files
kcl fmt your_config_path

Display of formatting files

  • Before formatting
import     math
mixin DeploymentMixin:
service:str ="my-service"
schema DeploymentBase:
name: str
image : str
schema Deployment[replicas] ( DeploymentBase ) :
replicas : int = replicas
command: [str ]
labels: {str: str}
deploy = Deployment(replicas = 3){}
  • After formatting
import math

mixin DeploymentMixin:
service: str = "my-service"

schema DeploymentBase:
name: str
image: str

schema Deployment[replicas](DeploymentBase):
mixin [DeploymentMixin]
replicas: int = replicas
command: [str]
labels: {str:str}

deploy = Deployment(replicas=3) {}


This command formats all kcl files of the current crate.

kcl fmt [flags]

# Format the single file
kcl fmt /path/to/file.k

# Format all files in this folder recursively
kcl fmt ./...

-h, --help help for fmt