KclLib 0.12.3

dotnet add package KclLib --version 0.12.3
                    
NuGet\Install-Package KclLib -Version 0.12.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KclLib" Version="0.12.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KclLib" Version="0.12.3" />
                    
Directory.Packages.props
<PackageReference Include="KclLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KclLib --version 0.12.3
                    
#r "nuget: KclLib, 0.12.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KclLib@0.12.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KclLib&version=0.12.3
                    
Install as a Cake Addin
#tool nuget:?package=KclLib&version=0.12.3
                    
Install as a Cake Tool

KCL Artifact Library for .NET

This library is currently under development. Please check back later.

Quick Start

dotnet add package KclLib

Write the code

using KclLib.API;

var api = new API();
var execArgs = new ExecProgramArgs();
var path = Path.Combine("test_data", "schema.k");
execArgs.KFilenameList.Add(path);
var result = api.ExecProgram(execArgs);
Console.WriteLine(result.YamlResult);

Developing and Testing

  • Install cargo
  • Install dotnet 8.0+
cargo build --release
dotnet test

API Reference

ExecProgram

Execute KCL file with arguments and return the JSON/YAML result.

<details><summary>Example</summary> <p>

The content of schema.k is

schema AppConfig:
    replicas: int

app: AppConfig {
    replicas: 2
}

C# Code

using KclLib.API;

var execArgs = new ExecProgramArgs();
var path = "schema.k"
execArgs.KFilenameList.Add(path);
var result = new API().ExecProgram(execArgs);

</p> </details>

ParseFile

Parse KCL single file to Module AST JSON string with import dependencies and parse errors.

<details><summary>Example</summary> <p>

The content of schema.k is

schema AppConfig:
    replicas: int

app: AppConfig {
    replicas: 2
}

C# Code

using KclLib.API;

var path = "schema.k"
var args = new ParseFileArgs { Path = path };
var result = new API().ParseFile(args);

</p> </details>

ParseProgram

Parse KCL program with entry files and return the AST JSON string.

<details><summary>Example</summary> <p>

The content of schema.k is

schema AppConfig:
    replicas: int

app: AppConfig {
    replicas: 2
}

C# Code

using KclLib.API;

var path = "schema.k";
var args = new ParseProgramArgs();
args.Paths.Add(path);
var result = new API().ListOptions(args);

</p> </details>

LoadPackage

LoadPackage provides users with the ability to parse KCL program and semantic model information including symbols, types, definitions, etc.

<details><summary>Example</summary> <p>

The content of schema.k is

schema AppConfig:
    replicas: int

app: AppConfig {
    replicas: 2
}

C# Code

using KclLib.API;

var path = "schema.k";
var args = new LoadPackageArgs();
args.ResolveAst = true;
args.ParseArgs = new ParseProgramArgs();
args.ParseArgs.Paths.Add(path);
var result = new API().LoadPackage(args);

</p> </details>

ListVariables

ListVariables provides users with the ability to parse KCL program and get all variables by specs.

<details><summary>Example</summary> <p>

The content of schema.k is

schema AppConfig:
    replicas: int

app: AppConfig {
    replicas: 2
}

C# Code

using KclLib.API;

var api = new API();
var args = new ListVariablesArgs();
var path = "schema.k";
args.Files.Add(path);
var result = api.ListVariables(args);

</p> </details>

ListOptions

ListOptions provides users with the ability to parse KCL program and get all option information.

<details><summary>Example</summary> <p>

The content of options.k is

a = option("key1")
b = option("key2", required=True)
c = {
    metadata.key = option("metadata-key")
}

C# Code

using KclLib.API;

var path = "options.k";
var args = new ParseProgramArgs();
args.Paths.Add(path);
var result = new API().ListOptions(args);

</p> </details>

GetSchemaTypeMapping

Get schema type mapping defined in the program.

<details><summary>Example</summary> <p>

The content of schema.k is

schema AppConfig:
    replicas: int

app: AppConfig {
    replicas: 2
}

C# Code

using KclLib.API;

var path = "schema.k";
var execArgs = new ExecProgramArgs();
execArgs.KFilenameList.Add(path);
var args = new GetSchemaTypeMappingArgs();
args.ExecArgs = execArgs;
var result = new API().GetSchemaTypeMapping(args);

</p> </details>

OverrideFile

Override KCL file with arguments. See https://www.kcl-lang.io/docs/user_docs/guides/automation for more override spec guide.

<details><summary>Example</summary> <p>

The content of main.k is

a = 1
b = {
    "a": 1
    "b": 2
}

C# Code

using KclLib.API;

var args = new OverrideFileArgs
{
    File = "main.k",
};
args.Specs.Add("b.a=2");
var result = new API().OverrideFile(args);

</p> </details>

FormatCode

Format the code source.

<details><summary>Example</summary> <p>

C# Code

using KclLib.API;

string sourceCode = "schema Person:\n" + "    name:   str\n" + "    age:    int\n" + "    check:\n"
    + "        0 <   age <   120\n";
string expectedFormattedCode = "schema Person:\n" + "    name: str\n" + "    age: int\n\n" + "    check:\n"
    + "        0 < age < 120\n\n";
var api = new API();
var args = new FormatCodeArgs();
args.Source = sourceCode;
var result = api.FormatCode(args);

</p> </details>

FormatPath

Format KCL file or directory path contains KCL files and returns the changed file paths.

<details><summary>Example</summary> <p>

The content of format_path.k is

schema Person:
    name:   str
    age:    int

    check:
        0 <   age <   120

C# Code

using KclLib.API;

var api = new API();
var args = new FormatPathArgs();
var path = "format_path.k";
args.Path = path;
var result = api.FormatPath(args);

</p> </details>

LintPath

Lint files and return error messages including errors and warnings.

<details><summary>Example</summary> <p>

The content of lint_path.k is

import math

a = 1

C# Code

using KclLib.API;

var path = "lint_path.k"
var args = new LintPathArgs();
args.Paths.Add(path);
var result = new API().LintPath(args);
bool foundWarning = result.Results.Any(warning => warning.Contains("Module 'math' imported but unused"));

</p> </details>

ValidateCode

Validate code using schema and JSON/YAML data strings.

<details><summary>Example</summary> <p>

C# Code

using KclLib.API;

string code = @"
schema Person:
    name: str
    age: int
    check:
        0 < age < 120
";
string data = "{\"name\": \"Alice\", \"age\": 10}";
var args = new ValidateCodeArgs
{
    Code = code,
    Data = data,
    Format = "json"
};
var result = new API().ValidateCode(args);

</p> </details>

Rename

Rename all the occurrences of the target symbol in the files. This API will rewrite files if they contain symbols to be renamed. Return the file paths that got changed.

<details><summary>Example</summary> <p>

The content of main.k is

a = 1
b = a

C# Code

using KclLib.API;

RenameArgs args = RenameArgs.newBuilder().setPackageRoot(".").setSymbolPath("a")
        .addFilePaths("main.k").setNewName("a2").build();
API apiInstance = new API();
RenameResult result = apiInstance.rename(args);

</p> </details>

RenameCode

Rename all the occurrences of the target symbol and return the modified code if any code has been changed. This API won't rewrite files but return the changed code.

<details><summary>Example</summary> <p>

C# Code

using KclLib.API;

var args = new RenameCodeArgs
{
    PackageRoot = "/mock/path",
    SymbolPath = "a",
    SourceCodes = { { "/mock/path/main.k", "a = 1\nb = a" } },
    NewName = "a2"
};
var result = new API().RenameCode(args);

</p> </details>

Test

Test KCL packages with test arguments.

<details><summary>Example</summary> <p>

C# Code

using KclLib.API;

var pkg = Path.Combine(parentDirectory, "test_data", "testing");
var args = new TestArgs();
args.PkgList.Add(pkg + "/...");
var result = new API().Test(args);

</p> </details>

LoadSettingsFiles

Load the setting file config defined in kcl.yaml

<details><summary>Example</summary> <p>

The content of kcl.yaml is

kcl_cli_configs:
  strict_range_check: true
kcl_options:
  - key: key
    value: value

C# Code

using KclLib.API;

var workDir = ".";
var settingsFile = "kcl.yaml";
var args = new LoadSettingsFilesArgs
{
    WorkDir = workDir,
};
args.Files.Add(settingsFile);
var result = new API().LoadSettingsFiles(args);

</p> </details>

UpdateDependencies

Download and update dependencies defined in the kcl.mod file and return the external package name and location list.

<details><summary>Example</summary> <p>

The content of module/kcl.mod is

[package]
name = "mod_update"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" }
flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" }

C# Code

using KclLib.API;

var manifestPath = "module";
var args = new UpdateDependenciesArgs { ManifestPath = manifestPath };
var result = new API().UpdateDependencies(args);

</p> </details>

Call ExecProgram with external dependencies

<details><summary>Example</summary> <p>

The content of module/kcl.mod is

[package]
name = "mod_update"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" }
flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" }

The content of module/main.k is

import helloworld
import flask

a = helloworld.The_first_kcl_program

C# Code

using KclLib.API;

API api = new API();

var manifestPath = "module";
var testFile = Path.Combine(manifestPath, "main.k");
var updateArgs = new UpdateDependenciesArgs { ManifestPath = manifestPath };
var depResult = new API().UpdateDependencies(updateArgs);
var execArgs = new ExecProgramArgs();
execArgs.KFilenameList.Add(testFile);
execArgs.ExternalPkgs.AddRange(depResult.ExternalPkgs);
var execResult = new API().ExecProgram(execArgs);

</p> </details>

GetVersion

Return the KCL service version information.

<details><summary>Example</summary> <p>

C# Code

using KclLib.API;

var result = new API().GetVersion(new GetVersionArgs());

</p> </details>

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.12.3 141 12/12/2025
0.12.2 439 12/10/2025
0.12.1 685 12/2/2025
0.12.0 191 11/24/2025
0.11.2 204 5/7/2025
0.11.1 253 2/7/2025
0.11.0 227 12/19/2024
0.11.0-alpha.1 154 12/6/2024
0.10.8 241 11/5/2024
0.10.7 221 10/28/2024
0.10.6 227 10/24/2024
0.10.5 206 10/23/2024
0.10.4 239 10/23/2024
0.10.3 234 10/15/2024
0.10.2 264 10/12/2024
0.10.0 289 9/16/2024
0.10.0-rc.1 151 9/5/2024
0.10.0-beta.2 177 8/22/2024
0.10.0-beta.1 147 8/14/2024
0.10.0-alpha.2 96 8/5/2024
Loading failed