π¨βπ» Building Your First Method (Simplified Workflow)ο
Now that you understand what it means to implement a method, hereβs how to actually build one β step by step β using the simplified βruntime-basedβ approach.
Weβll use the Advanced WordCloud method as a real-world example, you can download the full WordCloud Advanced json json definition.
π 1. Choose the Execution Tool or Libraryο
In this case we use wordcloud_cli
(https://github.com/amueller/word_cloud), which can be cloned from the public repository and run from shell.
This tool accepts command-line options for all parameters, making it ideal for CCP.
π 2. Define Your Goalο
In this case: generate a word cloud image from a text file.
We want the method to be flexible, so users can customize:
Input text file
Image size
Number of words
Font size range
Optional stopwords or mask image
π 3. Create a new empty method and define itο
in the π Method / Algorithm Importer page, fill the form for the creation of the new method
π³ 4. Select a Docker Imageο
For this example, we use a public image with Python:
{
"inputs": {
"ccpimage": {
"id": "ccpimage",
"title": "Runtime",
"description": "The image of the runtime to use for method execution. This depends on the infrastructure specific protocol for interacting with registries.",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": "url",
"contentMediaType": "text/plain",
"default": "python:3.9.19",
"readOnly": false
}
}
}
}
π 3. Prepare Inputs and Parametersο
In this case, we define input fields like:
file_url
(text file URL)width
,height
Optional:
blacklist_url
,colormask_url
,max_words
,min_font_size
,max_font_size
and the other inputs
the generated json is:
{
"inputs": {
"file_url": {
"id": "file_url",
"title": "File url",
"description": "Url of the text file of words to build the word cloud",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": "remotefile",
"contentMediaType": "text/plain",
"default": ""
}
},
"width": {
"id": "width",
"title": "Image width",
"description": "output image width",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": "number",
"contentMediaType": "text/plain",
"default": "1024"
}
}
}
}
π§ 5. Write the Deploy Scriptο
This script prepares the environment. In this case:
pip install wordcloud
curl -L {{file_url}} -o /ccp_data/input.txt
[ -n "{{blacklist_url}}" ] && curl -L {{blacklist_url}} -o /ccp_data/blacklist.txt
[ -n "{{colormask_url}}" ] && curl -L {{colormask_url}} -o /ccp_data/colormask.png
It handles:
Dependency installation
Download of required and optional input files
π 6. Write the Execute Scriptο
This script runs the method. It uses shell logic to build the command dynamically:
cmd="wordcloud_cli --text /ccp_data/input.txt --imagefile /ccp_data/wordcloud.png"
cmd="$cmd --width {{width}} --height {{height}}"
[ -n "{{max_words}}" ] && cmd="$cmd --max_words {{max_words}}"
[ -n "{{min_font_size}}" ] && cmd="$cmd --min_font_size {{min_font_size}}"
[ -n "{{max_font_size}}" ] && cmd="$cmd --max_font_size {{max_font_size}}"
[ -n "{{blacklist_url}}" ] && cmd="$cmd --stopwords /ccp_data/blacklist.txt"
[ -n "{{colormask_url}}" ] && cmd="$cmd --colormask /ccp_data/colormask.png"
eval $cmd
π This allows conditional inclusion of optional parameters.
π¦ 7. Save the Outputο
The script writes the image to:
/ccp_data/wordcloud.png
Any file saved to /ccp_data/
, like the input.txt downloaded in the deploy script, becomes downloadable for the user.
β Summaryο
Element | Description |
---|---|
Docker image | python:3.9.19 |
Install tool | pip install wordcloud |
Inputs | URLs and numbers (some optional) |
Deploy script | Prepares environment and downloads files |
Execute script | Builds and runs the CLI command |
Output | /ccp_data/wordcloud.png |
π Want to Build Your Own Method?ο
Before you start, make sure you understand the basic concepts of CCP methods.
π See: π£ Concepts for Beginners
What About Advanced Users?ο
The method structure explained in this guide is meant to help you get started quickly, even if youβre not a developer.
However, if youβre building a methods that:
Needs custom dependencies or environments
Must run on secure/private code
Should be reusable in production
β¦you should consider the consolidation workflow.
Consolidated Methodsο
A consolidated method:
Uses a custom Docker image with all dependencies pre-installed
Embeds the algorithm code inside the image (no need to clone anything)
Can work without internet access and is more stable over time
Requires a bit more technical setup, but offers maximum control
π See the π³ Consolidation Guide for full details.