从 Python 应用调用 OpenWhisk 操作?

invoking OpenWhisk actions from a Python app?

我想知道从 Python 应用程序调用 OpenWhisk 操作的最简单方法是什么? 也许等同于 https://github.com/apache/incubator-openwhisk-client-js/ but in Python. I know that there used to be a Python-based CLI (https://github.com/apache/incubator-openwhisk-client-python),但我还没有找到任何关于如何从我的 Python 脚本中重用它的文档。

从 Python 应用程序调用操作需要您向平台 API 发送 HTTP 请求。 Python 没有官方的 OpenWhisk SDK。

示例代码展示了如何使用 requests 库调用平台 API。

import subprocess
import requests

APIHOST = 'https://openwhisk.ng.bluemix.net'
AUTH_KEY = subprocess.check_output("wsk property get --auth", shell=True).split()[2] 
NAMESPACE = 'whisk.system'
ACTION = 'utils/echo'
PARAMS = {'myKey':'myValue'};
BLOCKING = 'true'
RESULT = 'true'

url = APIHOST + '/api/v1/namespaces/' + NAMESPACE + '/actions/' + ACTION
user_pass = AUTH_KEY.split(':')
response = requests.post(url, json=PARAMS, params={'blocking': BLOCKING, 'result': RESULT}, auth=(user_pass[0], user_pass[1]))
print(response.text)

完整 API 的 Swagger 文档可用 here

有一个 open issue 可以创建一个 Python 客户端库来使这更容易。