Skip to Content
avatar image
Former Member

Leonardo ML Functional API Python examples

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.
Thanks.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    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 = "https://sandbox.api.sap.com/ml/timeseriesforecast/inference_sync"
    
    resp = requests.post(url, data=json.dumps(data), headers=headers)
    print(r.text)
    
    Add comment
    10|10000 characters needed characters exceeded