πŸ‘¨β€πŸ’» 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

define the method


🐳 4. Select a Docker Image

For this example, we use a public image with Python:

select a docker image

{
    "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

input file

input number

and the other inputs

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

deploy script


πŸš€ 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.

execute script


πŸ“¦ 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.