Package: ivcap-client
ivcap_client: Python library to interact with an IVCAP ClusterA python library to interact with the published API of IVCAP. Almost
all the code of this library is auto generated byopenapi-python-clientfromIVCAP'sopenapi3.jsonfile.UsageCreate a clientCall a ServiceUse ModelsExample: Order a ServiceThings to knowCreate a clientfromivcap_clientimportAuthenticatedClientclient=AuthenticatedClient(base_url="https://api.ivcap.net",token="JWT")Currently, the best way to get the token is to use theivcap cliand executeivcap context get access-token. Obviously,
this assumes that the current context ofivcapis the same as the one the above
client is for.By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.client=AuthenticatedClient(base_url="https://internal_api.example.com",token="SuperSecretToken",verify_ssl="/path/to/certificate_bundle.pem",)You can also disable certificate validation altogether, but beware thatthis is a security risk.client=AuthenticatedClient(base_url="https://internal_api.example.com",token="SuperSecretToken",verify_ssl=False)Call a Service and use Modelsfromivcap_client.modelsimportServiceListRTfromivcap_client.api.serviceimportservice_listfromivcap_client.typesimportResponseservices:ServiceListRT=service_list.sync(client=client,limit=1)# or if you need more info (e.g. status_code)response:Response[ServiceListRT]=service_list.sync_detailed(client=client,limit)Or do the same thing with an async version:fromivcap_client.modelsimportServiceListRTfromivcap_client.api.serviceimportservice_listfromivcap_client.typesimportResponseservices:ServiceListRT=awaitservice_list.asyncio(client=client,limit=2)# or if you need more info (e.g. status_code)response:Response[ServiceListRT]=awaitservice_list.asyncio_detailed(client=client,limit)Use ModelsThe above call returns aServiceListRTobject. To find out what attributes that contains:>>>services.to_dict().keys()dict_keys(['at-time','links','services'])and to pretty-print the list of services:importpprintpp=pprint.PrettyPrinter(indent=2)>>>pp.pprint(list(map(lambdael:el.to_dict(),services.services)))[{'id':'urn:ivcap:service:8773f79e-d46c-559a-a63c-54c4e2a9d9a1','links':{...},'name':'infer-with-paddle-paddle','provider':{'id':'urn:ivcap:provider:4c65b865-df6a-4977-982a-f96b19c1fda0'}},{'id':'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed','links':{...},'name':'Gradient Text Image','provider':{'id':'urn:ivcap:provider:4c65b865-df6a-4977-982a-f96b19c1fda0'}}]Example: Order a ServiceTo get the list of parameters for a particular service, using the list of services we obtained above:fromivcap_client.api.serviceimportservice_readfromivcap_client.modelsimportServiceStatusRTexampleService:ServiceStatusRT=service_read.sync(client=client,id=services.services[0].id)>>>exampleService.to_dict().keys()dict_keys(['id','links','parameters','account','description','metadata','name','provider','tags'])>>>exampleService.description'Creates an image with a customizable text.'>>>pp.pprint(list(map(lambdael:el.to_dict(),exampleService.parameters)))[{'description':'','label':'Message to display','name':'msg','optional':False,'options':[],'type':'string','unit':''},{'description':'','label':'Image artifact to use as background','name':'img-art','optional':True,'options':[],'type':'artifact','unit':''},{'description':'','label':'Image url (external) to use as background','name':'img-url','optional':True,'options':[],'type':'string','unit':''}]To order a service:fromtypingimportListfromivcap_client.api.orderimportorder_createfromivcap_client.modelsimportOrderRequestT,ParameterT,OrderRequestT,OrderStatusRTimg_url='https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'service_id='urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed'account_id=os.environ['IVCAP_ACCOUNT_ID']p=[ParameterT(name='msg',value='Hello World'),ParameterT(name='img-url',value=img_url)]req=OrderRequestT(name='test 1',parameters=p,service_id=service_id,account_id=account_id)order_resp=order_create.sync_detailed(client=client,json_body=req)order:OrderStatusRT=order_resp.parsedifnotorder:raiseException(f'Order request failed: ${order_resp.status_code}')>>>pp.pprint(order.to_dict()){'account':{'id':'urn:ivcap:account:4c65b865-df6a-4977-982a-f96b19c1fda0'},'id':'urn:ivcap:order:cd04597a-2d55-4f1c-906c-995450f30599','links':{'self':'http://localhost:8080/1/orders/cd04597a-2d55-4f1c-906c-995450f30599'},'name':'test 1','ordered_at':'2023-05-03T16:31:04+10:00','parameters':[{'name':'msg','value':'Hello World'},{'name':'img-url','value':'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'}],'products':[],'service':{'id':'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed','links':{'self':'http://localhost:8080/1/services/85f4586e-af1e-5200-94ba-0be8651740ed'}},'status':'pending'}Later on we can check on the order:fromivcap_client.api.orderimportorder_readostatus=order_read.sync(client=client,id=order.id)>>>pp.pprint(ostatus.to_dict()){'account':{'id':'urn:ivcap:account:4c65b865-df6a-4977-982a-f96b19c1fda0'},'finished_at':'2023-05-04T00:29:19Z','id':'urn:ivcap:order:de15958e-9575-444a-aa25-69ff259e2345','links':{...},'name':'test 1','ordered_at':'2023-05-04T00:28:29Z','parameters':[{'name':'msg','value':'Hello World'},{'name':'img-url','value':'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'}],'products':[{'id':'urn:ivcap:artifact:eae6aceb-aec5-4eec-a918-bd4575891168','links':{...},'mime-type':'image/png','name':'out.png','size':0}],'service':{'id':'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed','links':{...}},'started_at':'2023-05-04T00:28:45Z','status':'succeeded'}Things to knowEvery path/method combo becomes a Python module with four functions:sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aRequest, optionally withparsedset if the request was successful.asyncio: Likesyncbut async instead of blockingasyncio_detailed: Likesync_detailedbut async instead of blockingAll path/query params, and bodies become method arguments.If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)Any endpoint which did not have a tag will be inivcap_client.api.default