Skip to Content

Leonardo ML Functional API Python examples

Sep 20, 2017 at 09:19 PM


avatar image

Could anyone please provide example API usage with Python? Currently the "Generate Code" option displays examples in Javascript, Java, Swift, Curl, ABAP and SAPUI5. For example this answer describes using prodimgclassifier and I would like to know ways to call other APIs such as time-series prediction, language translation etc.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

William Ayd Oct 06, 2017 at 07:11 PM

The link you provided makes this out to be a little more complicated than it needs to be. At it's core with any REST service, you need the url you want to retrieve, the headers you'd like to send along with it and in the case of a POST the data you want to send.

Here's an example for the Time Series Forecast API you mentioned. Assuming you have the requests library installed (if not, install it) all you have to do is specify the url, create the headers and data as a dict, and allow the requests library to take care of the post action for you.

import requests
import json

headers = {
    'APIKey' : 'your API Key',
    'Accept' : 'application/json',
    'content-type' : 'multipart/form-data'

data = {
    'options' : 'string'

url = ""

resp =, data=json.dumps(data), headers=headers)
10 |10000 characters needed characters left characters exceeded