ivcap_client 0.40.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ivcap_client-0.40.3/AUTHORS.md +5 -0
- ivcap_client-0.40.3/LICENSE +29 -0
- ivcap_client-0.40.3/PKG-INFO +231 -0
- ivcap_client-0.40.3/README.md +212 -0
- ivcap_client-0.40.3/pyproject.toml +46 -0
- ivcap_client-0.40.3/src/ivcap_client/__init__.py +26 -0
- ivcap_client-0.40.3/src/ivcap_client/api/__init__.py +1 -0
- ivcap_client-0.40.3/src/ivcap_client/api/artifact/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/artifact/artifact_list.py +330 -0
- ivcap_client-0.40.3/src/ivcap_client/api/artifact/artifact_read.py +183 -0
- ivcap_client-0.40.3/src/ivcap_client/api/artifact/artifact_upload.py +368 -0
- ivcap_client-0.40.3/src/ivcap_client/api/aspect/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/aspect/aspect_create.py +265 -0
- ivcap_client-0.40.3/src/ivcap_client/api/aspect/aspect_list.py +450 -0
- ivcap_client-0.40.3/src/ivcap_client/api/aspect/aspect_read.py +183 -0
- ivcap_client-0.40.3/src/ivcap_client/api/aspect/aspect_retract.py +185 -0
- ivcap_client-0.40.3/src/ivcap_client/api/aspect/aspect_update.py +254 -0
- ivcap_client-0.40.3/src/ivcap_client/api/metadata/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/metadata/metadata_add.py +264 -0
- ivcap_client-0.40.3/src/ivcap_client/api/metadata/metadata_list.py +418 -0
- ivcap_client-0.40.3/src/ivcap_client/api/metadata/metadata_read.py +183 -0
- ivcap_client-0.40.3/src/ivcap_client/api/metadata/metadata_revoke.py +185 -0
- ivcap_client-0.40.3/src/ivcap_client/api/metadata/metadata_update_record.py +286 -0
- ivcap_client-0.40.3/src/ivcap_client/api/openapi/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/openapi/openapi_1openapiopenapi3_json.py +83 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/order_create.py +210 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/order_list.py +330 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/order_logs.py +230 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/order_metadata.py +298 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/order_products.py +298 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/order_read.py +183 -0
- ivcap_client-0.40.3/src/ivcap_client/api/order/order_top.py +211 -0
- ivcap_client-0.40.3/src/ivcap_client/api/queue/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/queue/queue_create.py +206 -0
- ivcap_client-0.40.3/src/ivcap_client/api/queue/queue_delete.py +176 -0
- ivcap_client-0.40.3/src/ivcap_client/api/queue/queue_dequeue.py +204 -0
- ivcap_client-0.40.3/src/ivcap_client/api/queue/queue_enqueue.py +252 -0
- ivcap_client-0.40.3/src/ivcap_client/api/queue/queue_list.py +330 -0
- ivcap_client-0.40.3/src/ivcap_client/api/queue/queue_read.py +183 -0
- ivcap_client-0.40.3/src/ivcap_client/api/search/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/search/search_search.py +360 -0
- ivcap_client-0.40.3/src/ivcap_client/api/service/__init__.py +0 -0
- ivcap_client-0.40.3/src/ivcap_client/api/service/service_create_service.py +258 -0
- ivcap_client-0.40.3/src/ivcap_client/api/service/service_delete.py +176 -0
- ivcap_client-0.40.3/src/ivcap_client/api/service/service_list.py +330 -0
- ivcap_client-0.40.3/src/ivcap_client/api/service/service_read.py +183 -0
- ivcap_client-0.40.3/src/ivcap_client/api/service/service_update.py +287 -0
- ivcap_client-0.40.3/src/ivcap_client/artifact.py +154 -0
- ivcap_client-0.40.3/src/ivcap_client/aspect.py +133 -0
- ivcap_client-0.40.3/src/ivcap_client/client/__init__.py +13 -0
- ivcap_client-0.40.3/src/ivcap_client/client/client.py +273 -0
- ivcap_client-0.40.3/src/ivcap_client/errors.py +25 -0
- ivcap_client-0.40.3/src/ivcap_client/excpetions.py +34 -0
- ivcap_client-0.40.3/src/ivcap_client/ivcap.py +500 -0
- ivcap_client-0.40.3/src/ivcap_client/models/__init__.py +115 -0
- ivcap_client-0.40.3/src/ivcap_client/models/add_meta_rt.py +61 -0
- ivcap_client-0.40.3/src/ivcap_client/models/artifact_list_item.py +119 -0
- ivcap_client-0.40.3/src/ivcap_client/models/artifact_list_item_status.py +12 -0
- ivcap_client-0.40.3/src/ivcap_client/models/artifact_list_rt.py +139 -0
- ivcap_client-0.40.3/src/ivcap_client/models/artifact_status_rt.py +212 -0
- ivcap_client-0.40.3/src/ivcap_client/models/artifact_status_rt_status.py +12 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspect_idrt.py +61 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspect_list_item_rt.py +146 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspect_list_item_rt_content.py +43 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspect_list_rt.py +163 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspect_rt.py +172 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspect_rt_content.py +43 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspectcreate_body.py +48 -0
- ivcap_client-0.40.3/src/ivcap_client/models/aspectupdate_body.py +48 -0
- ivcap_client-0.40.3/src/ivcap_client/models/bad_request_t.py +63 -0
- ivcap_client-0.40.3/src/ivcap_client/models/basic_workflow_opts_t.py +171 -0
- ivcap_client-0.40.3/src/ivcap_client/models/createqueueresponse.py +102 -0
- ivcap_client-0.40.3/src/ivcap_client/models/invalid_parameter_t.py +81 -0
- ivcap_client-0.40.3/src/ivcap_client/models/invalid_scopes_t.py +73 -0
- ivcap_client-0.40.3/src/ivcap_client/models/link_t.py +77 -0
- ivcap_client-0.40.3/src/ivcap_client/models/list_meta_rt.py +161 -0
- ivcap_client-0.40.3/src/ivcap_client/models/message_list.py +110 -0
- ivcap_client-0.40.3/src/ivcap_client/models/messagestatus.py +61 -0
- ivcap_client-0.40.3/src/ivcap_client/models/metadata_list_item_rt.py +111 -0
- ivcap_client-0.40.3/src/ivcap_client/models/metadata_list_item_rt_aspect.py +48 -0
- ivcap_client-0.40.3/src/ivcap_client/models/metadata_record_rt.py +162 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_list_item.py +161 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_list_item_status.py +14 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_list_rt.py +138 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_metadata_list_item_rt.py +86 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_request_t.py +118 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_status_rt.py +225 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_status_rt_status.py +14 -0
- ivcap_client-0.40.3/src/ivcap_client/models/order_top_result_item.py +95 -0
- ivcap_client-0.40.3/src/ivcap_client/models/parameter_def_t.py +166 -0
- ivcap_client-0.40.3/src/ivcap_client/models/parameter_opt_t.py +70 -0
- ivcap_client-0.40.3/src/ivcap_client/models/parameter_t.py +70 -0
- ivcap_client-0.40.3/src/ivcap_client/models/partial_meta_list_t.py +98 -0
- ivcap_client-0.40.3/src/ivcap_client/models/partial_product_list_t.py +98 -0
- ivcap_client-0.40.3/src/ivcap_client/models/payload_for_create_endpoint.py +84 -0
- ivcap_client-0.40.3/src/ivcap_client/models/product_list_item_t.py +117 -0
- ivcap_client-0.40.3/src/ivcap_client/models/publishedmessage.py +101 -0
- ivcap_client-0.40.3/src/ivcap_client/models/queue_list_item.py +99 -0
- ivcap_client-0.40.3/src/ivcap_client/models/queue_list_result.py +124 -0
- ivcap_client-0.40.3/src/ivcap_client/models/readqueueresponse.py +173 -0
- ivcap_client-0.40.3/src/ivcap_client/models/reference_t.py +70 -0
- ivcap_client-0.40.3/src/ivcap_client/models/resource_memory_t.py +72 -0
- ivcap_client-0.40.3/src/ivcap_client/models/resource_not_found_t.py +70 -0
- ivcap_client-0.40.3/src/ivcap_client/models/search_list_rt.py +115 -0
- ivcap_client-0.40.3/src/ivcap_client/models/service_definition_t.py +177 -0
- ivcap_client-0.40.3/src/ivcap_client/models/service_list_item.py +139 -0
- ivcap_client-0.40.3/src/ivcap_client/models/service_list_rt.py +136 -0
- ivcap_client-0.40.3/src/ivcap_client/models/service_status_rt.py +159 -0
- ivcap_client-0.40.3/src/ivcap_client/models/service_status_rt_status.py +10 -0
- ivcap_client-0.40.3/src/ivcap_client/models/workflow_t.py +111 -0
- ivcap_client-0.40.3/src/ivcap_client/order.py +135 -0
- ivcap_client-0.40.3/src/ivcap_client/py.typed +1 -0
- ivcap_client-0.40.3/src/ivcap_client/service.py +229 -0
- ivcap_client-0.40.3/src/ivcap_client/types.py +54 -0
- ivcap_client-0.40.3/src/ivcap_client/utils.py +128 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ivcap_client
|
|
3
|
+
Version: 0.40.3
|
|
4
|
+
Summary: A client library for accessing an IVCAP cluster
|
|
5
|
+
Author: Max Ott
|
|
6
|
+
Author-email: max.ott@csiro.au
|
|
7
|
+
Requires-Python: >=3.9,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Dist: attrs (>=21.3.0)
|
|
14
|
+
Requires-Dist: httpx (>=0.15.4,<0.24.0)
|
|
15
|
+
Requires-Dist: python-dateutil (>=2.8.0,<3.0.0)
|
|
16
|
+
Requires-Dist: tuspy (>=1.0.0)
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# ivcap_client: Python library to interact with an IVCAP Cluster
|
|
20
|
+
|
|
21
|
+
A python library to interact with the published API of IVCAP. Almost
|
|
22
|
+
all the code of this library is auto generated by [openapi-python-client](https://github.com/openapi-generators/openapi-python-client) from [IVCAP's](https://github.com/reinventingscience/ivcap-core/) `openapi3.json` file.
|
|
23
|
+
|
|
24
|
+
> CAUTION: This README is out of date, for the moment it is better to check out
|
|
25
|
+
> the examples in [examples](./examples). We'll try to fix this soon.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
* [Create a client](#create)
|
|
30
|
+
* [Call a Service](#call)
|
|
31
|
+
* [Use Models](#use)
|
|
32
|
+
* [Example: Order a Service](#order)
|
|
33
|
+
* [Things to know](#know)
|
|
34
|
+
|
|
35
|
+
### Create a client <a name="create"></a>
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from ivcap_client import AuthenticatedClient
|
|
39
|
+
|
|
40
|
+
client = AuthenticatedClient(base_url="https://api.ivcap.net", token="JWT")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
> Currently, the best way to get the token is to use the [ivcap cli](https://github.com/reinventingscience/ivcp-cli) and execute `ivcap context get access-token`. Obviously,
|
|
44
|
+
this assumes that the current context of `ivcap` is the same as the one the above
|
|
45
|
+
client is for.
|
|
46
|
+
|
|
47
|
+
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.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
client = AuthenticatedClient(
|
|
51
|
+
base_url="https://internal_api.example.com",
|
|
52
|
+
token="SuperSecretToken",
|
|
53
|
+
verify_ssl="/path/to/certificate_bundle.pem",
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You can also disable certificate validation altogether, but beware that **this is a security risk**.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
client = AuthenticatedClient(
|
|
61
|
+
base_url="https://internal_api.example.com",
|
|
62
|
+
token="SuperSecretToken",
|
|
63
|
+
verify_ssl=False
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Call a Service and use Models<a name="call"></a>
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from ivcap_client.models import ServiceListRT
|
|
71
|
+
from ivcap_client.api.service import service_list
|
|
72
|
+
from ivcap_client.types import Response
|
|
73
|
+
|
|
74
|
+
services: ServiceListRT = service_list.sync(client=client, limit=1)
|
|
75
|
+
# or if you need more info (e.g. status_code)
|
|
76
|
+
response: Response[ServiceListRT] = service_list.sync_detailed(client=client, limit)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or do the same thing with an async version:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from ivcap_client.models import ServiceListRT
|
|
83
|
+
from ivcap_client.api.service import service_list
|
|
84
|
+
from ivcap_client.types import Response
|
|
85
|
+
|
|
86
|
+
services: ServiceListRT = await service_list.asyncio(client=client, limit=2)
|
|
87
|
+
# or if you need more info (e.g. status_code)
|
|
88
|
+
response: Response[ServiceListRT] = await service_list.asyncio_detailed(client=client, limit)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Use Models<a name="use"></a>
|
|
92
|
+
|
|
93
|
+
The above call returns a `ServiceListRT` object. To find out what attributes that contains:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
>>> services.to_dict().keys()
|
|
97
|
+
dict_keys(['at-time', 'links', 'services'])
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
and to pretty-print the list of services:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import pprint
|
|
104
|
+
pp = pprint.PrettyPrinter(indent=2)
|
|
105
|
+
|
|
106
|
+
>>> pp.pprint(list(map(lambda el: el.to_dict(), services.services)))
|
|
107
|
+
[ { 'id': 'urn:ivcap:service:8773f79e-d46c-559a-a63c-54c4e2a9d9a1',
|
|
108
|
+
'links': { ... },
|
|
109
|
+
'name': 'infer-with-paddle-paddle',
|
|
110
|
+
'provider': { 'id': 'urn:ivcap:provider:4c65b865-df6a-4977-982a-f96b19c1fda0'}},
|
|
111
|
+
{ 'id': 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed',
|
|
112
|
+
'links': { ... },
|
|
113
|
+
'name': 'Gradient Text Image',
|
|
114
|
+
'provider': { 'id': 'urn:ivcap:provider:4c65b865-df6a-4977-982a-f96b19c1fda0'}
|
|
115
|
+
}]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Example: Order a Service <a name="order"></a>
|
|
119
|
+
|
|
120
|
+
To get the list of parameters for a particular service, using the list of services we obtained above:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from ivcap_client.api.service import service_read
|
|
124
|
+
from ivcap_client.models import ServiceStatusRT
|
|
125
|
+
|
|
126
|
+
exampleService:ServiceStatusRT = service_read.sync(client=client, id=services.services[0].id)
|
|
127
|
+
>>> exampleService.to_dict().keys()
|
|
128
|
+
dict_keys(['id', 'links', 'parameters', 'account', 'description', 'metadata', 'name', 'provider', 'tags'])
|
|
129
|
+
>>> exampleService.description
|
|
130
|
+
'Creates an image with a customizable text.'
|
|
131
|
+
>>> pp.pprint(list(map(lambda el: el.to_dict(), exampleService.parameters)))
|
|
132
|
+
[ { 'description': '',
|
|
133
|
+
'label': 'Message to display',
|
|
134
|
+
'name': 'msg',
|
|
135
|
+
'optional': False,
|
|
136
|
+
'options': [],
|
|
137
|
+
'type': 'string',
|
|
138
|
+
'unit': ''},
|
|
139
|
+
{ 'description': '',
|
|
140
|
+
'label': 'Image artifact to use as background',
|
|
141
|
+
'name': 'img-art',
|
|
142
|
+
'optional': True,
|
|
143
|
+
'options': [],
|
|
144
|
+
'type': 'artifact',
|
|
145
|
+
'unit': ''},
|
|
146
|
+
{ 'description': '',
|
|
147
|
+
'label': 'Image url (external) to use as background',
|
|
148
|
+
'name': 'img-url',
|
|
149
|
+
'optional': True,
|
|
150
|
+
'options': [],
|
|
151
|
+
'type': 'string',
|
|
152
|
+
'unit': ''}]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
To order a service:
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from typing import List
|
|
159
|
+
from ivcap_client.api.order import order_create
|
|
160
|
+
from ivcap_client.models import OrderRequestT, ParameterT, OrderRequestT, OrderStatusRT
|
|
161
|
+
|
|
162
|
+
img_url = 'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'
|
|
163
|
+
service_id = 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed'
|
|
164
|
+
account_id = os.environ['IVCAP_ACCOUNT_ID']
|
|
165
|
+
|
|
166
|
+
p = [
|
|
167
|
+
ParameterT(name='msg', value='Hello World'),
|
|
168
|
+
ParameterT(name='img-url', value=img_url)
|
|
169
|
+
]
|
|
170
|
+
req = OrderRequestT(name='test 1', parameters=p, service_id=service_id , account_id=account_id)
|
|
171
|
+
order_resp = order_create.sync_detailed(client=client, json_body=req)
|
|
172
|
+
order:OrderStatusRT = order_resp.parsed
|
|
173
|
+
if not order:
|
|
174
|
+
raise Exception(f'Order request failed: ${order_resp.status_code}')
|
|
175
|
+
|
|
176
|
+
>>> pp.pprint(order.to_dict())
|
|
177
|
+
{ 'account': {'id': 'urn:ivcap:account:4c65b865-df6a-4977-982a-f96b19c1fda0'},
|
|
178
|
+
'id': 'urn:ivcap:order:cd04597a-2d55-4f1c-906c-995450f30599',
|
|
179
|
+
'links': { 'self': 'http://localhost:8080/1/orders/cd04597a-2d55-4f1c-906c-995450f30599'},
|
|
180
|
+
'name': 'test 1',
|
|
181
|
+
'ordered_at': '2023-05-03T16:31:04+10:00',
|
|
182
|
+
'parameters': [ {'name': 'msg', 'value': 'Hello World'},
|
|
183
|
+
{ 'name': 'img-url',
|
|
184
|
+
'value': 'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'}],
|
|
185
|
+
'products': [],
|
|
186
|
+
'service': { 'id': 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed',
|
|
187
|
+
'links': { 'self': 'http://localhost:8080/1/services/85f4586e-af1e-5200-94ba-0be8651740ed'}},
|
|
188
|
+
'status': 'pending'}
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Later on we can check on the order:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from ivcap_client.api.order import order_read
|
|
196
|
+
|
|
197
|
+
ostatus = order_read.sync(client=client, id=order.id)
|
|
198
|
+
>>> pp.pprint(ostatus.to_dict())
|
|
199
|
+
{ 'account': {'id': 'urn:ivcap:account:4c65b865-df6a-4977-982a-f96b19c1fda0'},
|
|
200
|
+
'finished_at': '2023-05-04T00:29:19Z',
|
|
201
|
+
'id': 'urn:ivcap:order:de15958e-9575-444a-aa25-69ff259e2345',
|
|
202
|
+
'links': { ... },
|
|
203
|
+
'name': 'test 1',
|
|
204
|
+
'ordered_at': '2023-05-04T00:28:29Z',
|
|
205
|
+
'parameters': [ {'name': 'msg', 'value': 'Hello World'},
|
|
206
|
+
{ 'name': 'img-url',
|
|
207
|
+
'value': 'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'}],
|
|
208
|
+
'products': [ { 'id': 'urn:ivcap:artifact:eae6aceb-aec5-4eec-a918-bd4575891168',
|
|
209
|
+
'links': { ... },
|
|
210
|
+
'mime-type': 'image/png',
|
|
211
|
+
'name': 'out.png',
|
|
212
|
+
'size': 0}],
|
|
213
|
+
'service': { 'id': 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed',
|
|
214
|
+
'links': { ... }},
|
|
215
|
+
'started_at': '2023-05-04T00:28:45Z',
|
|
216
|
+
'status': 'succeeded'}
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Things to know<a name="know"></a>
|
|
221
|
+
|
|
222
|
+
1. Every path/method combo becomes a Python module with four functions:
|
|
223
|
+
1. `sync`: Blocking request that returns parsed data (if successful) or `None`
|
|
224
|
+
1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
|
|
225
|
+
1. `asyncio`: Like `sync` but async instead of blocking
|
|
226
|
+
1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
|
|
227
|
+
|
|
228
|
+
1. All path/query params, and bodies become method arguments.
|
|
229
|
+
1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
|
|
230
|
+
1. Any endpoint which did not have a tag will be in `ivcap_client.api.default`
|
|
231
|
+
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# ivcap_client: Python library to interact with an IVCAP Cluster
|
|
2
|
+
|
|
3
|
+
A python library to interact with the published API of IVCAP. Almost
|
|
4
|
+
all the code of this library is auto generated by [openapi-python-client](https://github.com/openapi-generators/openapi-python-client) from [IVCAP's](https://github.com/reinventingscience/ivcap-core/) `openapi3.json` file.
|
|
5
|
+
|
|
6
|
+
> CAUTION: This README is out of date, for the moment it is better to check out
|
|
7
|
+
> the examples in [examples](./examples). We'll try to fix this soon.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
* [Create a client](#create)
|
|
12
|
+
* [Call a Service](#call)
|
|
13
|
+
* [Use Models](#use)
|
|
14
|
+
* [Example: Order a Service](#order)
|
|
15
|
+
* [Things to know](#know)
|
|
16
|
+
|
|
17
|
+
### Create a client <a name="create"></a>
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from ivcap_client import AuthenticatedClient
|
|
21
|
+
|
|
22
|
+
client = AuthenticatedClient(base_url="https://api.ivcap.net", token="JWT")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> Currently, the best way to get the token is to use the [ivcap cli](https://github.com/reinventingscience/ivcp-cli) and execute `ivcap context get access-token`. Obviously,
|
|
26
|
+
this assumes that the current context of `ivcap` is the same as the one the above
|
|
27
|
+
client is for.
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
client = AuthenticatedClient(
|
|
33
|
+
base_url="https://internal_api.example.com",
|
|
34
|
+
token="SuperSecretToken",
|
|
35
|
+
verify_ssl="/path/to/certificate_bundle.pem",
|
|
36
|
+
)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You can also disable certificate validation altogether, but beware that **this is a security risk**.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
client = AuthenticatedClient(
|
|
43
|
+
base_url="https://internal_api.example.com",
|
|
44
|
+
token="SuperSecretToken",
|
|
45
|
+
verify_ssl=False
|
|
46
|
+
)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Call a Service and use Models<a name="call"></a>
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from ivcap_client.models import ServiceListRT
|
|
53
|
+
from ivcap_client.api.service import service_list
|
|
54
|
+
from ivcap_client.types import Response
|
|
55
|
+
|
|
56
|
+
services: ServiceListRT = service_list.sync(client=client, limit=1)
|
|
57
|
+
# or if you need more info (e.g. status_code)
|
|
58
|
+
response: Response[ServiceListRT] = service_list.sync_detailed(client=client, limit)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or do the same thing with an async version:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from ivcap_client.models import ServiceListRT
|
|
65
|
+
from ivcap_client.api.service import service_list
|
|
66
|
+
from ivcap_client.types import Response
|
|
67
|
+
|
|
68
|
+
services: ServiceListRT = await service_list.asyncio(client=client, limit=2)
|
|
69
|
+
# or if you need more info (e.g. status_code)
|
|
70
|
+
response: Response[ServiceListRT] = await service_list.asyncio_detailed(client=client, limit)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Use Models<a name="use"></a>
|
|
74
|
+
|
|
75
|
+
The above call returns a `ServiceListRT` object. To find out what attributes that contains:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
>>> services.to_dict().keys()
|
|
79
|
+
dict_keys(['at-time', 'links', 'services'])
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
and to pretty-print the list of services:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import pprint
|
|
86
|
+
pp = pprint.PrettyPrinter(indent=2)
|
|
87
|
+
|
|
88
|
+
>>> pp.pprint(list(map(lambda el: el.to_dict(), services.services)))
|
|
89
|
+
[ { 'id': 'urn:ivcap:service:8773f79e-d46c-559a-a63c-54c4e2a9d9a1',
|
|
90
|
+
'links': { ... },
|
|
91
|
+
'name': 'infer-with-paddle-paddle',
|
|
92
|
+
'provider': { 'id': 'urn:ivcap:provider:4c65b865-df6a-4977-982a-f96b19c1fda0'}},
|
|
93
|
+
{ 'id': 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed',
|
|
94
|
+
'links': { ... },
|
|
95
|
+
'name': 'Gradient Text Image',
|
|
96
|
+
'provider': { 'id': 'urn:ivcap:provider:4c65b865-df6a-4977-982a-f96b19c1fda0'}
|
|
97
|
+
}]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Example: Order a Service <a name="order"></a>
|
|
101
|
+
|
|
102
|
+
To get the list of parameters for a particular service, using the list of services we obtained above:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from ivcap_client.api.service import service_read
|
|
106
|
+
from ivcap_client.models import ServiceStatusRT
|
|
107
|
+
|
|
108
|
+
exampleService:ServiceStatusRT = service_read.sync(client=client, id=services.services[0].id)
|
|
109
|
+
>>> exampleService.to_dict().keys()
|
|
110
|
+
dict_keys(['id', 'links', 'parameters', 'account', 'description', 'metadata', 'name', 'provider', 'tags'])
|
|
111
|
+
>>> exampleService.description
|
|
112
|
+
'Creates an image with a customizable text.'
|
|
113
|
+
>>> pp.pprint(list(map(lambda el: el.to_dict(), exampleService.parameters)))
|
|
114
|
+
[ { 'description': '',
|
|
115
|
+
'label': 'Message to display',
|
|
116
|
+
'name': 'msg',
|
|
117
|
+
'optional': False,
|
|
118
|
+
'options': [],
|
|
119
|
+
'type': 'string',
|
|
120
|
+
'unit': ''},
|
|
121
|
+
{ 'description': '',
|
|
122
|
+
'label': 'Image artifact to use as background',
|
|
123
|
+
'name': 'img-art',
|
|
124
|
+
'optional': True,
|
|
125
|
+
'options': [],
|
|
126
|
+
'type': 'artifact',
|
|
127
|
+
'unit': ''},
|
|
128
|
+
{ 'description': '',
|
|
129
|
+
'label': 'Image url (external) to use as background',
|
|
130
|
+
'name': 'img-url',
|
|
131
|
+
'optional': True,
|
|
132
|
+
'options': [],
|
|
133
|
+
'type': 'string',
|
|
134
|
+
'unit': ''}]
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
To order a service:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from typing import List
|
|
141
|
+
from ivcap_client.api.order import order_create
|
|
142
|
+
from ivcap_client.models import OrderRequestT, ParameterT, OrderRequestT, OrderStatusRT
|
|
143
|
+
|
|
144
|
+
img_url = 'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'
|
|
145
|
+
service_id = 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed'
|
|
146
|
+
account_id = os.environ['IVCAP_ACCOUNT_ID']
|
|
147
|
+
|
|
148
|
+
p = [
|
|
149
|
+
ParameterT(name='msg', value='Hello World'),
|
|
150
|
+
ParameterT(name='img-url', value=img_url)
|
|
151
|
+
]
|
|
152
|
+
req = OrderRequestT(name='test 1', parameters=p, service_id=service_id , account_id=account_id)
|
|
153
|
+
order_resp = order_create.sync_detailed(client=client, json_body=req)
|
|
154
|
+
order:OrderStatusRT = order_resp.parsed
|
|
155
|
+
if not order:
|
|
156
|
+
raise Exception(f'Order request failed: ${order_resp.status_code}')
|
|
157
|
+
|
|
158
|
+
>>> pp.pprint(order.to_dict())
|
|
159
|
+
{ 'account': {'id': 'urn:ivcap:account:4c65b865-df6a-4977-982a-f96b19c1fda0'},
|
|
160
|
+
'id': 'urn:ivcap:order:cd04597a-2d55-4f1c-906c-995450f30599',
|
|
161
|
+
'links': { 'self': 'http://localhost:8080/1/orders/cd04597a-2d55-4f1c-906c-995450f30599'},
|
|
162
|
+
'name': 'test 1',
|
|
163
|
+
'ordered_at': '2023-05-03T16:31:04+10:00',
|
|
164
|
+
'parameters': [ {'name': 'msg', 'value': 'Hello World'},
|
|
165
|
+
{ 'name': 'img-url',
|
|
166
|
+
'value': 'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'}],
|
|
167
|
+
'products': [],
|
|
168
|
+
'service': { 'id': 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed',
|
|
169
|
+
'links': { 'self': 'http://localhost:8080/1/services/85f4586e-af1e-5200-94ba-0be8651740ed'}},
|
|
170
|
+
'status': 'pending'}
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Later on we can check on the order:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from ivcap_client.api.order import order_read
|
|
178
|
+
|
|
179
|
+
ostatus = order_read.sync(client=client, id=order.id)
|
|
180
|
+
>>> pp.pprint(ostatus.to_dict())
|
|
181
|
+
{ 'account': {'id': 'urn:ivcap:account:4c65b865-df6a-4977-982a-f96b19c1fda0'},
|
|
182
|
+
'finished_at': '2023-05-04T00:29:19Z',
|
|
183
|
+
'id': 'urn:ivcap:order:de15958e-9575-444a-aa25-69ff259e2345',
|
|
184
|
+
'links': { ... },
|
|
185
|
+
'name': 'test 1',
|
|
186
|
+
'ordered_at': '2023-05-04T00:28:29Z',
|
|
187
|
+
'parameters': [ {'name': 'msg', 'value': 'Hello World'},
|
|
188
|
+
{ 'name': 'img-url',
|
|
189
|
+
'value': 'https://juststickers.in/wp-content/uploads/2016/07/go-programming-language.png'}],
|
|
190
|
+
'products': [ { 'id': 'urn:ivcap:artifact:eae6aceb-aec5-4eec-a918-bd4575891168',
|
|
191
|
+
'links': { ... },
|
|
192
|
+
'mime-type': 'image/png',
|
|
193
|
+
'name': 'out.png',
|
|
194
|
+
'size': 0}],
|
|
195
|
+
'service': { 'id': 'urn:ivcap:service:85f4586e-af1e-5200-94ba-0be8651740ed',
|
|
196
|
+
'links': { ... }},
|
|
197
|
+
'started_at': '2023-05-04T00:28:45Z',
|
|
198
|
+
'status': 'succeeded'}
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Things to know<a name="know"></a>
|
|
203
|
+
|
|
204
|
+
1. Every path/method combo becomes a Python module with four functions:
|
|
205
|
+
1. `sync`: Blocking request that returns parsed data (if successful) or `None`
|
|
206
|
+
1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
|
|
207
|
+
1. `asyncio`: Like `sync` but async instead of blocking
|
|
208
|
+
1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
|
|
209
|
+
|
|
210
|
+
1. All path/query params, and bodies become method arguments.
|
|
211
|
+
1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
|
|
212
|
+
1. Any endpoint which did not have a tag will be in `ivcap_client.api.default`
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "ivcap_client"
|
|
3
|
+
version = "0.40.3"
|
|
4
|
+
description = "A client library for accessing an IVCAP cluster"
|
|
5
|
+
|
|
6
|
+
authors = ["Max Ott <max.ott@csiro.au>",
|
|
7
|
+
"openapi-python-client <https://github.com/openapi-generators/openapi-python-client>"]
|
|
8
|
+
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
|
|
11
|
+
include = ["CHANGELOG.md", "src/ivcap_sdk_client/py.typed"]
|
|
12
|
+
|
|
13
|
+
[tool.poetry.dependencies]
|
|
14
|
+
python = "^3.9"
|
|
15
|
+
httpx = ">=0.15.4,<0.24.0"
|
|
16
|
+
attrs = ">=21.3.0"
|
|
17
|
+
python-dateutil = "^2.8.0"
|
|
18
|
+
tuspy = ">=1.0.0"
|
|
19
|
+
|
|
20
|
+
[tool.poetry.dev-dependencies]
|
|
21
|
+
|
|
22
|
+
[tool.poetry.group.dev.dependencies]
|
|
23
|
+
openapi-python-client = ">=0.15.0"
|
|
24
|
+
pytest = "^7.1.3"
|
|
25
|
+
pytest-cov = "^4.1.0"
|
|
26
|
+
Sphinx = "^5.2.3"
|
|
27
|
+
myst-nb = "^0.17.1"
|
|
28
|
+
autoapi = "^2.0.1"
|
|
29
|
+
sphinx-autoapi = "^2.0.0"
|
|
30
|
+
sphinx-rtd-theme = "^1.0.0"
|
|
31
|
+
licenseheaders = "^0.8.8"
|
|
32
|
+
|
|
33
|
+
[tool.semantic_release]
|
|
34
|
+
version_variable = "pyproject.toml:version" # version location
|
|
35
|
+
branch = "main" # branch to make releases of
|
|
36
|
+
changelog_file = "CHANGELOG.md" # changelog file
|
|
37
|
+
build_command = "poetry build" # build dists
|
|
38
|
+
dist_path = "dist/" # where to put dists
|
|
39
|
+
upload_to_release = true # auto-create GitHub release
|
|
40
|
+
upload_to_pypi = false # don't auto-upload to PyPI
|
|
41
|
+
remove_dist = false # don't remove dists
|
|
42
|
+
patch_without_tag = true # patch release by default
|
|
43
|
+
|
|
44
|
+
[build-system]
|
|
45
|
+
requires = ["poetry-core>=1.0.0"]
|
|
46
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2023 Commonwealth Scientific and Industrial Research Organisation (CSIRO). All rights reserved.
|
|
3
|
+
# Use of this source code is governed by a BSD-style license that can be
|
|
4
|
+
# found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
5
|
+
#
|
|
6
|
+
""" A client library for accessing IVCAP """
|
|
7
|
+
|
|
8
|
+
# read version from installed package
|
|
9
|
+
try: # Python < 3.10 (backport)
|
|
10
|
+
from importlib_metadata import version
|
|
11
|
+
except ImportError:
|
|
12
|
+
from importlib.metadata import version
|
|
13
|
+
try:
|
|
14
|
+
__version__ = version("ivcap_client")
|
|
15
|
+
except Exception:
|
|
16
|
+
__version__ = "???" # should only happen when running the local examples
|
|
17
|
+
|
|
18
|
+
from .ivcap import IVCAP, URN
|
|
19
|
+
from .service import Service
|
|
20
|
+
from .order import Order
|
|
21
|
+
from .artifact import Artifact
|
|
22
|
+
# from .metadata import Metadata
|
|
23
|
+
|
|
24
|
+
# __all__ = (
|
|
25
|
+
# "IVCAP",
|
|
26
|
+
# )
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Contains methods for accessing the API"""
|
|
File without changes
|