# ๐Ÿ 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](/_static/imgs/input_ccpimage_python.png) --- ## ๐Ÿ“ Linking to Your Source Code You can use an input field like `repository` to let users specify the location of your code: ![Repository Input](/_static/imgs/input_repository.png) This repository will be cloned at runtime by the **deploy script**. --- ## ๐Ÿš€ Example Scripts ### ๐Ÿ”ง Deploy Script ```bash git clone {{repository}} repo pip install -r repo/requirements.txt ``` ### โ–ถ๏ธ Execute Script ```bash cd repo python myapp.py ``` These scripts go in your `method.json`: ```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: ```python 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](/_static/methods_examples/WordCloud-1.0.0.json) --- ## ๐Ÿ”— Related Pages - ๐Ÿ‘จโ€๐Ÿ’ป [Building simple methods](/01_quickstart/05_building_simple_method) - ๐Ÿ›  [Script syntax and placeholders](./06_scripts_and_placeholders) - ๐Ÿง [Docker image field (`ccpimage`)](./02_defining_ccpimage) - ๐Ÿ”ฃ [Structure of method.json](./07_method_json)