Skip to content

Build your first method

End-to-end walkthrough: scaffold a method that outputs some text.

Prerequisites

  • SimKit CLI installed. See installation. Download from the SimKit Web UI's CLI downloads page.
  • API key for your SimScale account. Your account needs MEMBER permission or higher on the component group you'll register components under (directly or inherited from a parent group), or you must be an admin of your organization.
  • A working directory. Anywhere on disk.

For end-users, methods cannot be run directly inside projects in SimScale Workbench. Method developers can use their method in a workflow and then use Workbench for manual testing.

Conventions

  • Each code block shows the command to run, ready to copy; the resulting output is described in the surrounding text or shown in a separate "Output" block.
  • <your-namespace> and <your-project-id> are placeholders to substitute. Pick a namespace you have MEMBER permission or higher on (typically <org>.<team>.tutorial or similar). All 1.0.0 references in this tutorial are snapshots — re-registerable while you iterate, so collisions with other tutorial-followers don't matter.

Step 1 — Configure simkit

simkit api-key set <YOUR_KEY>

Step 2 — Make a working directory and scaffold

mkdir text-output && cd text-output
simkit component init method <your-namespace>:text-output:1.0.0
Output
Initialized method at ./text_output.method.kts

simkit component init creates a single <id>.method.kts file in the current directory — the .kts is the whole component. The filename uses snake-case (text_output); the component reference uses the original casing (text-output).

Step 3 — Declare dependencies

Open text_output.method.kts. Replace the empty dependencies { } block with:

dependencies {
    dataType("simscale.test:native-test-method-output-item:1.0.0-SNAPSHOT-latest")
}

The data-type dependency will be the output. (If you forget a dependency, the build will fail in phase 2 with the missing reference named — easy to fix.)

The -SNAPSHOT-latest qualifier resolves the newest snapshot of that base version — appropriate for tutorial use. A concrete snapshot can be pinned instead by spelling out its full suffix (…:1.0.0-SNAPSHOT-2026-05-15-1). Released components pin to released versions (a bare …:1.0.0).

Step 4 — Define the data interface

The data interface declares the method's outputs (and inputs, if any). This method has only one output.

dataInterface {
    output("log", "simscale.test:native-test-method-output-item:1.0.0") { label("Output log") }
}

Step 5 — Define the configuration schema

This exposes user-tunable parameters. The only input is speed. Use only base SI units in methods to avoid handling units. Mapping dimensionals from workflow-type configuration to method configuration automatically converts to base SI units.

configurationSchema {
    dimensionalScalar("speed", metricUnits = UnitProfile(default = METER_PER_SECOND))
}

At the top of the file, add the following line to resolve the dependency to the METER_PER_SECOND measurement unit:

import com.simscale.workflows.framework.measurementunits.units.library.CompoundMetricUnits.METER_PER_SECOND
For IDE support in automatically importing, see Set up IDE support.

For nesting schemas of other data types, see example in Build your first workflow type.

Step 6 — Define the executable

All methods run as containerized apps. This tells us which Docker image to pull and which executable to run. The test method uses off-the-shelf python:3.12-alpine image. We will run a Python script that reads the input and writes some text as an output.

executable {
    imageName = "python"
    imageTag = "3.12-alpine"
    executableName = "python text_output.py"
}

text_output.py contains the business logic of your method. It will be defined in Step 13.

The Python image is for demonstration purposes only

The method engine only runs executable images hosted in a pre-defined list of registries. python:3.12-alpine comes from Docker Hub, so registering the method works, but running it fails.

Step 7 - Define the code generation language

Data classes can be generated based on method's configuration schema and data interface. Specify Python as code generation language:

codeGeneration { language = "python" }

The generated sources land next to the .kts by default; add outputDirectory = "build/generated/simkit/python" inside the block to keep them in a gitignorable subtree instead.

Save the file.

Step 8 — Build the component package

simkit component build
Output
→ [1/4] Pre-processing: text_output.method.kts
→ [2/4] Dependency resolution: 1 declared dependency, transitively resolved
→ [3/4] Description interpretation
→ [4/4] Definition interpretation: skipped (no definition-time blocks)
✓ Built <your-namespace>:text-output:1.0.0 → ./<your_namespace>:text-output:1.0.0-SNAPSHOT.method.json

The output JSON envelope lives next to the .kts. The following Python files are generated: * text_output_run_request.py -> Class for method's run request: Input request.json can be deserialized with this class. * text_output_run_context.py -> Class for method's context: Input context.json can be deserialized with this class. * text_output_config_data_model.py -> Contains classes for the method's configuration. * text_output_data_interface.py -> Contains data names of the method. * text_output_run_response.py -> Class for method's run response: Output response.json can be serialized with this class.

Method run starts by reading and interpreting request.json and context.json, and ends with writing a response.json. Generated data classes help with boilerplate.

Check method interface for more information on how to write the executable.

The built component is also testable at this point — no services needed. Drop a text_output.method.test.kts next to the .kts and run simkit component test. This method declares no validation rules, so a valid configuration produces no validation results:

import com.simscale.workflows.framework.measurementunits.units.library.CompoundMetricUnits.METER_PER_SECOND

methodTest {
    test("valid speed config passes validation") {
        validate { config(TextOutputConfigDataModel(speed = DimensionalScalar(value = 0.0, unit = METER_PER_SECOND))) }
            .shouldBeEmpty()
    }
}

Tests become more useful once the method declares definition-time behavior (a validation rule set, a resource estimation): use shouldHaveError to check that a rule rejects a bad configuration.

See the component tests reference for the full scope and assertion surface.

Step 9 — Register the package

simkit component register <your-namespace>:text-output:1.0.0-SNAPSHOT.method.json
Output
Successfully registered method version <your-namespace>:text-output:1.0.0

register walks the transitive dependency closure: anything your component depends on that the registry doesn't already have is registered first. The data type the method depends on is already registered, so this run is a single-component register.

Step 10 — Verify it landed

simkit component show <your-namespace>:text-output:1.0.0

Or open the SimKit Web UI and find your component under your namespace.

Step 11 — Write a request JSON

Save the following as request.json next to the package.

{
  "configuration": {
    "speed": {
      "value": 10.0,
      "unit": "m/s"
    }
  },
  "dataMap": {}
}

The configuration JSON key contains the method's configuration. The dataMap is empty because this method takes no input data. The configuration.speed corresponds to the configuration schema defined in Step 5.

The request.json will be written by our framework before the method is run. It is manually defined here for testing purposes: Methods can be run only in the context of a workflow-type. See Build your first workflow type for reference.

Step 12 — Write a context JSON

Save the following as context.json next to the package.

{
  "environment": "prod",
  "runId": "method.run:550e8400-e29b-41d4-a716-446655440000",
  "workflowRunId": "workflow.run:550e8400-e29b-41d4-a716-446655440001",
  "operationRunId": "operation.run:550e8400-e29b-41d4-a716-446655440002",
  "projectId": 42,
  "userId": 7,
  "trace": "trace-id-abc123"
}

The method's context is mostly useful for debugging. Similar to request.json, the context.json will be written by our framework before the method is run.

Step 13 — Write a Python script

Write a Python script that represents our method's business logic. The Python script reads request.json, outputs a text message to output-log.txt, and writes response.json to tell the system that the data output is at output-log.txt. Save this to text_output.py next to the package:

import json

from simscale.test.text_output_run_request import TextOutputRunRequestModel
from simscale.test.text_output_run_response import TextOutputRunResponseModel
from simscale.test.text_output_data_map_entries import TextOutputLogDataMapEntry

with open("request.json") as f:
    req = TextOutputRunRequestModel.model_validate(json.load(f))

with open("output-log.txt", "w") as f:
    f.write(f"Wow, you're running at {req.configuration.speed.value} {req.configuration.speed.unit}!")

response = TextOutputRunResponseModel(log=TextOutputLogDataMapEntry(path="output-log.txt"))

with open("response.json", "w") as f:
    f.write(response.model_dump_json(by_alias=True))

Step 14 — Run the app in a Docker container

To mimic running the method, run the following command:

docker run --rm -v $(pwd):/app -w /app python:3.12-slim sh -c "pip install pydantic && python text_output.py"

The command mounts the working directory to /app path inside the container. The directory contains the text_output.py, generated code, and the case-specific inputs (request.json and context.json). This mimics a real method run.

We install pydantic before running for demonstration purposes: All installation should happen when setting up your method's (real) Docker image.

Step 15 — See the result

Running the command produces: * output-log.txt -> Method's single data output, * response.json -> Contains path to the method's outputs.

cat output-log.txt
cat response.json

What you learned

  • The .kts file is the whole component — one file is everything the SimKit CLI needs.
  • Method is nothing but a containerized executable which you point to.
  • Methods cannot be executed via SimKit CLI, but can be easily tested locally due to a file-system based interface via request.json.

Where to next