๐ 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
:
๐ Linking to Your Source Code๏
You can use an input field like repository
to let users specify the location of your code:
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