In[]:=
cityDistance=APIFunction[{"city1"->"City","city2"->"City"},QuantityMagnitude@TravelDistance[#city1,#city2]&]
Out[]=
APIFunction[{city1City,city2City},QuantityMagnitude[TravelDistance[#city1,#city2]]&]
In[]:=
co=CloudDeploy[cityDistance,Permissions->"Public"]
Out[]=
CloudObject[
https://www.wolframcloud.com/obj/37d7a5ab-84f2-46e1-93ef-28b3943966e3
]
In[]:=
EmbedCode[co,"Python"]
Out[]=
Embeddable Code
Use the files and code below to call the Wolfram Cloud function from Python:
Dependencies
Install the
wolframclient
library.
​
Installation instructions:
Code
Copy to Clipboard
# -*- coding: utf-8 -*-​from __future__ import absolute_import, print_function, unicode_literalsfrom wolframclient.evaluation import WolframCloudSession​def call(city1, city2): Call the API using function input parameter values. If the API was deployed with an export formats set to JSON or WXF, the result is often a native Python type. with WolframCloudSession() as session: api_response = session.call('https://www.wolframcloud.com/obj/37d7a5ab-84f2-46e1-93ef-28b3943966e3', {'city1' : city1, 'city2' : city2}) return api_response.get()​