All Products
Search
Document Center

Security Center:python3 component

Last Updated:Oct 31, 2025

The Python3 component enables you to run Python 3 code.

Feature description

Action

Description

Scenarios

runPythonScript

Executes Python scripts.

Executes Python scripts.

Configuration example

This topic provides parameter configuration examples for each action of the Python3 component. You can import them as test playbooks. Through the visual flow editor, you can more intuitively understand and test the configuration parameters of each action, and easily master the functional logic and usage of the component. For the procedure, see Playbook import.

Note

You can save the example data as a JSON file first.

Example data

{
    "cells": [
        {
            "position": {
                "x": -550, 
                "y": -170
            }, 
            "size": {
                "width": 36, 
                "height": 36
            }, 
            "attrs": {
                "body": {
                    "fill": "white", 
                    "strokeOpacity": 0.95, 
                    "stroke": "#63ba4d", 
                    "strokeWidth": 2
                }, 
                "label": {
                    "text": "start", 
                    "fontSize": 12, 
                    "refX": 0.5, 
                    "refY": "100%", 
                    "refY2": 4, 
                    "textAnchor": "middle", 
                    "textVerticalAnchor": "top"
                }, 
                "path": {
                    "stroke": "#63ba4d"
                }
            }, 
            "visible": true, 
            "shape": "circle", 
            "id": "58d87b7d-28d9-4f0e-b135-4adc4f1a70e4", 
            "zIndex": 1, 
            "data": {
                "nodeType": "startEvent", 
                "appType": "basic", 
                "nodeName": "start", 
                "icon": "icon-circle", 
                "description": "Playbook start node. A playbook must have one and only one start node, which requires input data configuration for the playbook."
            }, 
            "markup": [
                {
                    "tagName": "circle", 
                    "selector": "body"
                }, 
                {
                    "tagName": "text", 
                    "selector": "label"
                }
            ], 
            "isNode": true
        }, 
        {
            "shape": "custom-edge", 
            "attrs": {
                "line": {
                    "stroke": "#63ba4d", 
                    "targetMarker": {
                        "stroke": "#63ba4d"
                    }
                }
            }, 
            "zIndex": 1, 
            "id": "5293c3f9-e1c9-4a49-b0eb-635067dc67e8", 
            "data": {
                "nodeType": "sequenceFlow", 
                "appType": "basic", 
                "isRequired": true, 
                "icon": "icon-upper-right-arrow"
            }, 
            "isNode": false, 
            "source": {
                "cell": "58d87b7d-28d9-4f0e-b135-4adc4f1a70e4"
            }, 
            "target": {
                "cell": "f2f5da63-9789-4967-8ef0-a84f04fd6e08"
            }, 
            "visible": true, 
            "router": {
                "name": "manhattan", 
                "args": {
                    "padding": 5, 
                    "excludeHiddenNodes": true, 
                    "excludeNodes": [
                        "clone_node_id"
                    ]
                }
            }, 
            "vertices": [ ]
        }, 
        {
            "position": {
                "x": 180, 
                "y": -160
            }, 
            "size": {
                "width": 36, 
                "height": 36
            }, 
            "attrs": {
                "body": {
                    "fill": "white", 
                    "strokeOpacity": 0.95, 
                    "stroke": "#63ba4d", 
                    "strokeWidth": 2
                }, 
                "path": {
                    "r": 12, 
                    "refX": "50%", 
                    "refY": "50%", 
                    "fill": "#63ba4d", 
                    "strokeOpacity": 0.95, 
                    "stroke": "#63ba4d", 
                    "strokeWidth": 4
                }, 
                "label": {
                    "text": "end", 
                    "fontSize": 12, 
                    "refX": 0.5, 
                    "refY": "100%", 
                    "refY2": 4, 
                    "textAnchor": "middle", 
                    "textVerticalAnchor": "top"
                }
            }, 
            "visible": true, 
            "shape": "circle", 
            "id": "317dd1be-2d20-460e-977e-1fc936ffb583", 
            "zIndex": 1, 
            "data": {
                "nodeType": "endEvent", 
                "appType": "basic", 
                "nodeName": "end", 
                "icon": "icon-radio-off-full", 
                "description": "end"
            }, 
            "markup": [
                {
                    "tagName": "circle", 
                    "selector": "body"
                }, 
                {
                    "tagName": "circle", 
                    "selector": "path"
                }, 
                {
                    "tagName": "text", 
                    "selector": "label"
                }
            ], 
            "isNode": true
        }, 
        {
            "position": {
                "x": -104, 
                "y": -185
            }, 
            "size": {
                "width": 137, 
                "height": 66
            }, 
            "view": "react-shape-view", 
            "attrs": {
                "label": {
                    "text": "python3"
                }
            }, 
            "shape": "activity", 
            "id": "1a98a6d1-bf7d-494b-a109-4767ab6b683c", 
            "data": {
                "componentName": "python3", 
                "appType": "component", 
                "nodeType": "action", 
                "icon": "https://sophon-gen-v2.oss-cn-zhangjiakou.aliyuncs.com/componentUpload/1680258193158_python3_logo.png?Expires=1745635126&OSSAccessKeyId=STS.NXFP************&Signature=v0E1aypTCVrWQkqLFygJKP7lohg%3D&security-token=CAIS2AJ1q6Ft5B2yfSjIr5vzG87foZl22KyFUBLSokwYY%2Fh22qDsqTz2IHhMenFpAegcv%2Fw%2BlGFZ6%2F8elrp6SJtIXleCZtF94oxN9h2gb4fb4yUAIjSK0s%2FLI3OaLjKm9u2wCryLYbGwU%2FOpbE%2B%2B5U0X6LDmdDKkckW4OJmS8%2FBOZcgWWQ%2FKBlgvRq0hRG1YpdQdKGHaONu0LxfumRCwNkdzvRdmgm4NgsbWgO%2Fks0OP3AOrlrBN%2Bdiuf8T9NvMBZskvD42Hu8VtbbfE3SJq7BxHybx7lqQs%2B02c5onDWwAJu0%2FXa7uEo4wydVNjFbM9A65Dqufxn%2Fpgt%2Braj4X7xhhEIOVJSSPbSZBbSxJNvU1RXDxQVcEYWxylurjnXvF%2Bs5c2%2B8hAf0rM946UoJvc3YDI5hWbc8mJsTnhSSTAEIv%2By8ptqoFOtH7DkLTHWR7hCtv2306G8%2BSFMytAXxqAASheMaPI1EtW9vmzJTiUzI1Mpy%2FK1KMvL%2B5YrTITRTgQenkGkLFgTOTzW2VSuoF6w%2BpSA8UDTPnYZlyFlgELihq4wDNkqqrtUToxub0PrpMEESyGVIWbCAK0XljETFRtwl7eMM99EaqvKTN8r6%2Bhxw2xWIDH5k25760sl0KS5qaCIAA%3D", 
                "ownType": "sys", 
                "zIndex": 1, 
                "tenantId": "baba", 
                "customInput": true, 
                "description": "Run Python3 scripts.", 
                "id": 0, 
                "name": "runPythonScript", 
                "operateType": "general", 
                "parameters": [
                    {
                        "dataType": "Complex", 
                        "defaultValue": "", 
                        "description": "Input parameters for the Python script", 
                        "name": "inputParams", 
                        "needCascader": false, 
                        "required": false, 
                        "tags": ""
                    }, 
                    {
                        "dataType": "Text", 
                        "defaultValue": "", 
                        "description": "Content of the Python script", 
                        "name": "pythonScript", 
                        "needCascader": false, 
                        "required": false, 
                        "tags": ""
                    }
                ], 
                "riskLevel": 2, 
                "nodeName": "python3", 
                "actionName": "runPythonScript", 
                "actionDisplayName": "runPythonScript", 
                "cascaderValue": [
                    {
                        "label": "DataFormat", 
                        "value": "${DataFormat}", 
                        "children": [ ]
                    }
                ], 
                "valueData": {
                    "pythonScript": "aW1wb3J0IGxvZ2dpbmcKZGVmIGV4ZWN1dGUgKHBhcmFtcyk6CiAgaXAgPSBwYXJhbXNbJ2lwJ10KICAjbG9nZ2luZy5pbmZvKCJlbnRlciBleGVjdXRlLGlwIGlzICIraXApCiAgc3VjY2Vzcz1UcnVlCiAgbWVzc2FnZT0nT0snCiAgZGF0YT1beyJpcCI6aXB9XQogIHJldHVybiAoc3VjY2VzcyxtZXNzYWdlLGRhdGEp", 
                    "inputParams": "[{\"fieldName\":\"ip\",\"fieldValue\":\"${DataFormat.datalist.*.ip}\",\"sampleData\":\"127.0.0.1\"}]", 
                    "keySampleMap": "{\"ip\":\"127.0.0.1\"}"
                }, 
                "status": "success"
            }, 
            "zIndex": 1
        }, 
        {
            "shape": "custom-edge", 
            "attrs": {
                "line": {
                    "stroke": "#63ba4d", 
                    "targetMarker": {
                        "stroke": "#63ba4d"
                    }
                }
            }, 
            "zIndex": 1, 
            "id": "629151e2-2f65-45ac-8992-6fc05b9b9e8f", 
            "data": {
                "nodeType": "sequenceFlow", 
                "appType": "basic", 
                "isRequired": true, 
                "icon": "icon-upper-right-arrow"
            }, 
            "isNode": false, 
            "visible": true, 
            "router": {
                "name": "manhattan", 
                "args": {
                    "padding": 5, 
                    "excludeHiddenNodes": true, 
                    "excludeNodes": [
                        "clone_node_id"
                    ]
                }
            }, 
            "source": {
                "cell": "1a98a6d1-bf7d-494b-a109-4767ab6b683c"
            }, 
            "target": {
                "cell": "317dd1be-2d20-460e-977e-1fc936ffb583"
            }, 
            "vertices": [ ]
        }, 
        {
            "position": {
                "x": -403, 
                "y": -185
            }, 
            "size": {
                "width": 137, 
                "height": 66
            }, 
            "view": "react-shape-view", 
            "attrs": {
                "label": {
                    "text": "DataFormat"
                }
            }, 
            "shape": "activity", 
            "id": "f2f5da63-9789-4967-8ef0-a84f04fd6e08", 
            "data": {
                "componentName": "DataFormat", 
                "appType": "component", 
                "nodeType": "action", 
                "icon": "https://sophon-gen-v2.oss-cn-zhangjiakou.aliyuncs.com/componentUpload/1719222281702_DataFormat_logo.png?Expires=1745635126&OSSAccessKeyId=STS.NXFP************&Signature=BrZznwYmLW%2BogLrdq1LEnGusLiA%3D&security-token=CAIS2AJ1q6Ft5B2yfSjIr5vzG87foZl22KyFUBLSokwYY%2Fh22qDsqTz2IHhMenFpAegcv%2Fw%2BlGFZ6%2F8elrp6SJtIXleCZtF94oxN9h2gb4fb4yUAIjSK0s%2FLI3OaLjKm9u2wCryLYbGwU%2FOpbE%2B%2B5U0X6LDmdDKkckW4OJmS8%2FBOZcgWWQ%2FKBlgvRq0hRG1YpdQdKGHaONu0LxfumRCwNkdzvRdmgm4NgsbWgO%2Fks0OP3AOrlrBN%2Bdiuf8T9NvMBZskvD42Hu8VtbbfE3SJq7BxHybx7lqQs%2B02c5onDWwAJu0%2FXa7uEo4wydVNjFbM9A65Dqufxn%2Fpgt%2Braj4X7xhhEIOVJSSPbSZBbSxJNvU1RXDxQVcEYWxylurjnXvF%2Bs5c2%2B8hAf0rM946UoJvc3YDI5hWbc8mJsTnhSSTAEIv%2By8ptqoFOtH7DkLTHWR7hCtv2306G8%2BSFMytAXxqAASheMaPI1EtW9vmzJTiUzI1Mpy%2FK1KMvL%2B5YrTITRTgQenkGkLFgTOTzW2VSuoF6w%2BpSA8UDTPnYZlyFlgELihq4wDNkqqrtUToxub0PrpMEESyGVIWbCAK0XljETFRtwl7eMM99EaqvKTN8r6%2Bhxw2xWIDH5k25760sl0KS5qaCIAA%3D", 
                "ownType": "sys", 
                "zIndex": 1, 
                "tenantId": "baba", 
                "customInput": false, 
                "description": "Generate new data", 
                "id": 0, 
                "name": "formatdata", 
                "operateType": "general", 
                "output": [ ], 
                "parameters": [
                    {
                        "dataType": "Complex", 
                        "defaultValue": "", 
                        "description": "Data to be transformed and generated", 
                        "enDescription": "", 
                        "name": "outputFields", 
                        "needCascader": false, 
                        "required": false, 
                        "tags": ""
                    }
                ], 
                "riskLevel": 2, 
                "nodeName": "DataFormat", 
                "actionName": "formatdata", 
                "actionDisplayName": "formatdata", 
                "cascaderValue": [ ], 
                "valueData": {
                    "outputFields": "[{\"fieldName\":\"ip\",\"fieldValue\":\"127.0.0.1\"}]"
                }, 
                "status": "success"
            }, 
            "zIndex": 1
        }, 
        {
            "shape": "custom-edge", 
            "attrs": {
                "line": {
                    "stroke": "#63ba4d", 
                    "targetMarker": {
                        "stroke": "#63ba4d"
                    }
                }
            }, 
            "zIndex": 1, 
            "id": "097a897e-5525-4227-9050-2d3bb3fa41e8", 
            "data": {
                "nodeType": "sequenceFlow", 
                "appType": "basic", 
                "isRequired": true, 
                "icon": "icon-upper-right-arrow"
            }, 
            "isNode": false, 
            "visible": true, 
            "router": {
                "name": "manhattan", 
                "args": {
                    "padding": 5, 
                    "excludeHiddenNodes": true, 
                    "excludeNodes": [
                        "clone_node_id"
                    ]
                }
            }, 
            "source": {
                "cell": "f2f5da63-9789-4967-8ef0-a84f04fd6e08"
            }, 
            "target": {
                "cell": "1a98a6d1-bf7d-494b-a109-4767ab6b683c"
            }, 
            "vertices": [ ]
        }
    ]
}

runPythonScript

Note

Python 3.0 code runs in a built-in Python 3.9 container environment that belongs to the current Alibaba Cloud account, with 0.25vCPU and 256MB memory. The maximum execution time for scripts is 600 seconds.

Configuration description

The component parameter configuration consists of two parts:

  • Parameter area: You need to configure parameter names and parameter values.

    • Parameter name: Supports customization. In Python code, the parameter value will be obtained through "execute["parameter name"]".

    • Parameter value: Supports constants, String, JSON, arrays, output values from preceding nodes, etc.

    • Test data: Used for testing Python code.

  • Code area: The component supports writing Python code online. The input parameter name of the execute method can be customized to receive parameters configured in the parameter area.

  • Execution result area:

    • Execution result: After clicking the Run button, you can view the Python code execution output or error messages in this area.

    • Execution log: You can view the output log, which helps users debug Python script errors, such as checking execution locations, calculation outputs, etc.

      Note
      • Only warn, info, and error log levels are supported.

      • Log output has a delay. You can click the Refresh button to get the latest information.

Example

The following figure shows a sample flow chart:

  • The input parameter name is ip, and the parameter value is the ip field value output from the preceding node (node name is "DataFormat").

  • Use "params" as the execute method input parameter to receive the ip parameter.

  • Output logs to the execution log through logging.info.

image