Skip to content

Commit 066f6b8

Browse files
authored
Client changes for is1865/enh-solvers-api (#21)
Client in sync with changes in api-server ITISFoundation/osparc-simcore#2150 - Changes API model for File resource - Deletes job_api and adds all functions in solver_api since it refers to solver jobs - Adds customized deserialization in _any_of.py - removed test_workflow.py: - osparc-simcore/tests/public-api : tests this API against master version of osparc-simcore stack - adds here a test that guarantees THESE changes work against production deployment of API - updated doc
1 parent 3764101 commit 066f6b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2818
-3893
lines changed

README.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ TODO: activate when service is up and running in production
1313

1414
Python client for osparc-simcore public web API
1515

16-
- API version: 0.4.0
17-
- Package version: 0.4.1
16+
- API version: 0.3.0
17+
- Package version: 0.4.2
1818
- Build package: org.openapitools.codegen.languages.PythonClientCodegen
1919

2020
## Requirements
@@ -23,7 +23,7 @@ Python 3.6+
2323

2424
## Installation & Usage
2525

26-
Install the latest release with
26+
Install the [latest release](https://github.com/ITISFoundation/osparc-simcore-python-client/releases) with
2727

2828
```sh
2929
pip install osparc
@@ -44,27 +44,45 @@ import osparc
4444
Please follow the installation procedure above and then run the following:
4545

4646
```python
47-
from __future__ import print_function
47+
import os
4848
import time
49+
4950
import osparc
50-
from osparc.rest import ApiException
51-
from pprint import pprint
52-
53-
# Defining host is optional and default to https://api.osparc.io
54-
configuration = osparc.Configuration()
55-
configuration.host = "https://api.osparc.io"
56-
57-
# Enter a context with an instance of the API client
58-
with osparc.ApiClient(configuration) as api_client:
59-
# Create an instance of the API class
60-
api_instance = osparc.MetaApi(api_client)
61-
62-
try:
63-
# Get Service Metadata
64-
api_response = api_instance.get_service_metadata()
65-
pprint(api_response)
66-
except ApiException as e:
67-
print("Exception when calling MetaApi->get_service_metadata: %s\n" % e)
51+
from osparc.models import File, Solver, Job, JobStatus, JobInputs, JobOutputs
52+
from osparc.api import FilesApi, SolversApi
53+
54+
cfg = osparc.Configuration(
55+
host=os.environ.get("OSPARC_API_URL", "http://127.0.0.1:8006"),
56+
username=os.environ.get("MY_API_KEY"),
57+
password=os.environ.get("MY_API_SECRET"),
58+
)
59+
60+
with osparc.ApiClient(cfg) as api_client:
61+
62+
files_api = FilesApi(api_client)
63+
input_file: File = files_api.upload_file(file="path/to/input-file.h5")
64+
65+
66+
solvers_api = SolversApi(api_client)
67+
solver: Solver = solvers_api.get_solver_release("simcore/services/comp/isolve", "1.2.3")
68+
69+
job: Job = solvers_api.create_job(
70+
solver.id,
71+
solver.version,
72+
JobInputs({"input_1": input_file, "input_2": 33, "input_3": False}),
73+
)
74+
75+
status: JobStatus = solvers_api.start_job(solver.id, solver.version, job.id)
76+
while not status.stopped_at:
77+
time.sleep(3)
78+
status = solvers_api.inspect_job(solver.id, solver.version, job.id)
79+
print("Solver progress", f"{status.progress}/100", flush=True)
80+
81+
outputs: JobOutputs = solvers_api.get_job_outputs(solver.id, solver.version, job.id)
82+
83+
print( f"Job {outputs.job_id} got these results:")
84+
for output_name, result in outputs.results.items():
85+
print(output_name, "=", result)
6886

6987
```
7088

0 commit comments

Comments
 (0)