Run a Python Function
/py-scripts/v1/do-eval/{scriptName}
Request
-
scriptName(required):
The name of the Python script
Response
200 Response
201 Response
400 Response
500 Response
Examples
Example 1
The following example runs the script named RandomRedDots. The
graphicsFlag
parameter is set to true
to
return the PNG image and the data from the function in JSON format.
curl -i -X POST --header "Authorization: Bearer ${token}" \
--header 'Content-Type: application/json' --header 'Accept: application/json' \
-d '{"graphicsFlag":true, "service":"LOW"}' \
"<oml-cloud-service-location-url>/oml/api/py-scripts/v1/do-eval/RandomRedDots"
Response Headers
The response headers are the following:
HTTP/1.1 200 OK
Date: Wed, 26 Aug 2020 20:48:58 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache, no-store, private
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1;mode=block
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
Set-Cookie: JSESSIONID=node01p78shsm2h9binj7jxzaipn0s652.node0; Path=/oml; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Response Body
The result of the REST endpoint is a JSON representation of the value returned from the Python script, which includes the image and the data. Image bytes are returned in PNG format. A portion of the returned value is:
{"result":[{"IMAGE":"iVBORw0KG...AAAAASUVORK5CYII=","DATA":"[{\"id\":1,\"val\":0.01},...,{\"id\":9,\"val\":0.09}]","ID":1}]}
Example 2
The following example runs the script named
test_seaborn_noinp
. The graphicsFlag
parameter
is set to true
to return the PNG image and the data from the
function in JSON format.
curl -i -k -X POST --header "Authorization: Bearer ${token}"
--header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"envName": "seaborn", "graphicsFlag": true}'
"<oml-cloud-service-locationurl>/oml/api/py-scripts/v1/do-eval/test_seaborn_noinp"
Response Body
The result of the REST endpoint is a JSON representation of the value returned from the Python script, which includes the image and the data. Image bytes are returned in PNG format.
{
"result": [
{
"IMAGE": "iVBORw0KGgoAAAAN......CAAAAAElFTkSuQmCC",
"DATA": "\"hello world\"",
"TITLE": "Dist plot",
"ID": 1
}
]
}