python

package
v0.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const FunctionNameProcess = "Process"

FunctionNameProcess is the name of the function to be called in the script

Variables

This section is empty.

Functions

This section is empty.

Types

type PythonNode

type PythonNode struct {
	Config PythonNodeConfiguration
	// contains filtered or unexported fields
}

PythonNode is an action component that executes Python scripts. It spawns a python3 subprocess for each message, passes input via stdin JSON, and reads the result from stdout JSON.

JSON rule chain DSL example:

{
  "id": "s1",
  "type": "x/python",
  "name": "Python处理",
  "configuration": {
    "script": "import json\ndata = json.loads(msg) if isinstance(msg, str) else msg\ndata['processed'] = True\nreturn json.dumps(data), metadata, msgType",
    "pythonPath": "python3",
    "timeout": "5s",
    "maxRunning": 10
  }
}

func (*PythonNode) Desc

func (x *PythonNode) Desc() string

Desc returns the component description

func (*PythonNode) Destroy

func (x *PythonNode) Destroy()

Destroy releases the resources of the component

func (*PythonNode) Init

func (x *PythonNode) Init(ruleConfig types.Config, configuration types.Configuration) error

Init initializes the component

func (*PythonNode) New

func (x *PythonNode) New() types.Node

New creates a new instance of PythonNode

func (*PythonNode) OnMsg

func (x *PythonNode) OnMsg(ctx types.RuleContext, msg types.RuleMsg)

OnMsg handles the message by executing the Python script

func (*PythonNode) Type

func (x *PythonNode) Type() string

Type returns the type of the component

type PythonNodeConfiguration

type PythonNodeConfiguration struct {
	Script     string `json:"script" label:"Script" desc:"Python script content or .py file path" required:"true"`
	PythonPath string `json:"pythonPath" label:"Python Path" desc:"Python interpreter path, uses system PATH by default"`
	Timeout    string `json:"timeout" label:"Timeout" desc:"Script execution timeout, e.g. 10s, 1m"`
	MaxRunning int    `json:"maxRunning" label:"Max Running" desc:"Max concurrent executions, default 1"`
}

PythonNodeConfiguration node configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL