๐Ÿ Writing Python-Based Methods๏ƒ

To implement a method in Python, you typically use the standard python Docker image via the ccpimage input.


๐Ÿณ Choosing the Python Runtime๏ƒ

Use ccpimage to select a Docker image like python:3.9.19:

Python Image


๐Ÿ“ Linking to Your Source Code๏ƒ

You can use an input field like repository to let users specify the location of your code:

Repository Input

This repository will be cloned at runtime by the deploy script.


๐Ÿš€ Example Scripts๏ƒ

๐Ÿ”ง Deploy Script๏ƒ

git clone {{repository}} repo
pip install -r repo/requirements.txt

โ–ถ๏ธ Execute Script๏ƒ

cd repo
python myapp.py

These scripts go in your method.json:

"additionalParameters": {
  "parameters": [
    {
      "name": "deploy-script",
      "value": [
        "git clone {{repository}} repo",
        "pip install -r repo/requirements.txt"
      ]
    },
    {
      "name": "execute-script",
      "value": [
        "cd repo",
        "python myapp.py"
      ]
    }
  ]
}

๐Ÿงช Tip: Use argparse to expose parameters๏ƒ

Your Python script should expose configurable parameters:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--input", required=True)
parser.add_argument("--output", required=True)
parser.add_argument("--threshold", type=float, default=0.5)
args = parser.parse_args()

๐Ÿ“„ Example Method๏ƒ

See the full WordCloud Example