Skip to content

SDK Modules

CoreClaw SDK provides core modules for Worker development.

The following SDK files are mandatory and must be placed in the project:

File NameMain Function
sdk.pyCore functionality module
sdk_pb2.pyEnhanced data processing module
sdk_pb2_grpc.pyNetwork communication module
File NameMain Function
sdk.jsCore functionality module
sdk_pb.jsEnhanced data processing module
sdk_grpc_pb.jsNetwork communication module
File NameMain Function
GoSdk/sdk.goCore functionality module
GoSdk/sdk.pb.goEnhanced data processing module
GoSdk/sdk_grpc.pb.goNetwork communication module

These files together form the script’s toolbox, providing all essential capabilities required for Worker execution and interaction with the platform’s backend system.


Retrieve configuration passed at script startup

When the script starts, external configuration parameters can be passed in (such as target website URLs, search keywords, etc.).

from sdk import CoreSDK
# Retrieve all input parameters as a dictionary
parameters = CoreSDK.Parameter.get_input_json_dict()
# Retrieve as raw JSON string
json_str = CoreSDK.Parameter.get_input_json_str()
const coresdk = require('./sdk')
// Retrieve as parsed JSON object
const inputJson = await coresdk.parameter.getInputJSONObject()
// Retrieve as raw JSON string
const jsonString = await coresdk.parameter.getInputJSONString()
import coresdk "test/GoSdk"
// Retrieve as raw JSON string
inputJSON, err := coresdk.Parameter.GetInputJSONString(ctx)

Use case: If you need to collect data from different websites for different tasks, simply pass different parameters without modifying the script code.


Record script execution progress

During execution, you can log messages at different levels. These logs will be displayed in the platform UI, making it easier to monitor execution status and troubleshoot issues.

from sdk import CoreSDK
CoreSDK.Log.debug("Connecting to target website...")
CoreSDK.Log.info("Successfully collected 10 news articles")
CoreSDK.Log.warn("Network latency detected")
CoreSDK.Log.error("Failed to access target website")
const coresdk = require('./sdk')
await coresdk.log.debug("Connecting to target website...")
await coresdk.log.info("Successfully collected 10 news articles")
await coresdk.log.warn("Network latency detected")
await coresdk.log.error("Failed to access target website")
coresdk.Log.Debug(ctx, "Connecting to target website...")
coresdk.Log.Info(ctx, "Successfully collected 10 news articles")
coresdk.Log.Warn(ctx, "Network latency detected")
coresdk.Log.Error(ctx, "Failed to access target website")
  • debug: Most detailed logs, recommended during development
  • info: Normal execution flow, recommended at key steps
  • warn: Potential issues that do not stop execution
  • error: Errors that require attention

Send collected data back to the platform

Once data is collected, it must be returned to the platform in two steps.


Before pushing any data, define the table structure—similar to defining column headers in Excel.

headers = [
{"label": "News Title", "key": "title", "format": "text"},
{"label": "Publish Time", "key": "publish_time", "format": "text"},
{"label": "Category", "key": "category", "format": "text"},
]
res = CoreSDK.Result.set_table_header(headers)
const headers = [
{ label: "News Title", key: "title", format: "text" },
{ label: "Publish Time", key: "publish_time", format: "text" },
{ label: "Category", key: "category", format: "text" },
]
await coresdk.result.setTableHeader(headers)
headers := []*coresdk.TableHeaderItem{
{Label: "News Title", Key: "title", Format: "text"},
{Label: "Publish Time", Key: "publish_time", Format: "text"},
{Label: "Category", Key: "category", Format: "text"},
}
res, err := coresdk.Result.SetTableHeader(ctx, headers)
  • label: Column name shown to users (recommended to use descriptive names)
  • key: Unique identifier used in code (recommended lowercase with underscores)
  • format: Data type, supported values:
    • "text": String / text
    • "integer": Integer
    • "boolean": Boolean (true / false)
    • "array": List / array
    • "object": Dictionary / object

news_data = [
{"title": "AI Breakthrough", "publish_time": "2023-10-01", "category": "Technology"},
{"title": "Stock Market Today", "publish_time": "2023-10-01", "category": "Finance"},
]
for i, news in enumerate(news_data):
res = CoreSDK.Result.push_data(news)
CoreSDK.Log.info(f"Pushed record {i + 1}: {news.get('title')}")
const newsData = [
{ title: "AI Breakthrough", publish_time: "2023-10-01", category: "Technology" },
{ title: "Stock Market Today", publish_time: "2023-10-01", category: "Finance" },
]
for (let i = 0; i < newsData.length; i++) {
await coresdk.result.pushData(newsData[i])
await coresdk.log.info(`Pushed record ${i + 1}: ${newsData[i].title}`)
}
for i, news := range newsData {
jsonBytes, _ := json.Marshal(news)
res, err := coresdk.Result.PushData(ctx, string(jsonBytes))
if err != nil {
coresdk.Log.Error(ctx, fmt.Sprintf("Failed to push data: %v", err))
return
}
coresdk.Log.Info(ctx, fmt.Sprintf("Pushed record %d", i+1))
}
  • Header definition and data pushing can be done in either order
  • Data keys must exactly match the header keys (case-sensitive)
  • Data must be pushed one record at a time
  • Logging after each push is recommended