Skip to content

Commit 80e7623

Browse files
committed
feat(client): bootstrap
1 parent f780426 commit 80e7623

File tree

93 files changed

+9607
-3
lines changed

Some content is hidden

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

93 files changed

+9607
-3
lines changed

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
randomname==0.2.1
22
httpx==0.27.0
3-
dataclasses-json==0.6.4
4-
dataclasses==0.6
5-
pytimeparse==1.1.8
3+
pytimeparse==1.1.8
4+
attrs = ">=22.2.0"
5+
python-dateutil = "^2.8.0"

scaleway_qaas_client/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
__pycache__/
2+
build/
3+
dist/
4+
*.egg-info/
5+
.pytest_cache/
6+
7+
# pyenv
8+
.python-version
9+
10+
# Environments
11+
.env
12+
.venv
13+
14+
# mypy
15+
.mypy_cache/
16+
.dmypy.json
17+
dmypy.json
18+
19+
# JetBrains
20+
.idea/
21+
22+
/coverage.xml
23+
/.coverage

scaleway_qaas_client/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from quantum_as_a_service_api_client.models import (
2+
ScalewayQaasV1Alpha1Platform as QaaSPlatform,
3+
)
4+
from quantum_as_a_service_api_client.models import (
5+
ScalewayQaasV1Alpha1PlatformAvailability as QaaSPlatformAvailability,
6+
)
7+
from quantum_as_a_service_api_client.models import (
8+
ScalewayQaasV1Alpha1PlatformTechnology as QaaSPlatformTechnology,
9+
)
10+
from quantum_as_a_service_api_client.models import ScalewayQaasV1Alpha1Job as QaaSJob
11+
from quantum_as_a_service_api_client.models import (
12+
ScalewayQaasV1Alpha1JobResult as QaaSJobResut,
13+
)
14+
from quantum_as_a_service_api_client.models import (
15+
ScalewayQaasV1Alpha1JobStatus as QaaSJobStatus,
16+
)
17+
from quantum_as_a_service_api_client.models import (
18+
ScalewayQaasV1Alpha1Session as QaaSSession,
19+
)
20+
from quantum_as_a_service_api_client.models import (
21+
ScalewayQaasV1Alpha1SessionStatus as QaaSSessionStatus,
22+
)
23+
from quantum_as_a_service_api_client.models import (
24+
ScalewayQaasV1Alpha1Application as QaaSApplication,
25+
)
26+
from quantum_as_a_service_api_client.models import (
27+
ScalewayQaasV1Alpha1Process as QaaSProcess,
28+
)
29+
from quantum_as_a_service_api_client.models import (
30+
ScalewayQaasV1Alpha1ProcessResult as QaaSProcessResult,
31+
)
32+
from quantum_as_a_service_api_client.models import (
33+
ScalewayQaasV1Alpha1ProcessStatus as QaaSProcessStatus,
34+
)

scaleway_qaas_client/client.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import json
2+
3+
from typing import List, Optional, Dict
4+
5+
from quantum_as_a_service_api_client.models import (
6+
CreateJobBody,
7+
CreateJobBodyCircuit,
8+
CreateSessionBody,
9+
TerminateSessionBody,
10+
ScalewayQaasV1Alpha1Platform,
11+
ScalewayQaasV1Alpha1Job,
12+
ScalewayQaasV1Alpha1JobResult,
13+
ScalewayQaasV1Alpha1Session,
14+
)
15+
16+
from quantum_as_a_service_api_client.api.sessions.create_session import (
17+
sync as create_session_sync,
18+
)
19+
from quantum_as_a_service_api_client.api.sessions.terminate_session import (
20+
sync as terminate_session_sync,
21+
)
22+
from quantum_as_a_service_api_client.api.sessions.delete_session import (
23+
sync_detailed as delete_session_sync,
24+
)
25+
from quantum_as_a_service_api_client.api.platforms.list_platforms import (
26+
sync as list_platforms_sync,
27+
)
28+
from quantum_as_a_service_api_client.api.jobs.create_job import (
29+
sync as create_job_sync,
30+
)
31+
from quantum_as_a_service_api_client.api.jobs.get_job import (
32+
sync as get_job_sync,
33+
)
34+
from quantum_as_a_service_api_client.api.jobs.list_job_results import (
35+
sync as list_job_result_sync,
36+
)
37+
38+
from quantum_as_a_service_api_client.client import Client
39+
40+
41+
__DEFAULT_URL = "https://api.scaleway.com/qaas/v1alpha1"
42+
43+
44+
class QaaSClient:
45+
def __init__(self, project_id: str, token: str, url: str = __DEFAULT_URL):
46+
self.__token = token
47+
self.__project_id = project_id
48+
49+
self.__client = Client(
50+
headers={"X-Auth-Token": self.__token},
51+
base_url=self.__url,
52+
timeout=10.0,
53+
verify_ssl="https" in url,
54+
)
55+
56+
def list_platforms(self, name: Optional[str]) -> List[ScalewayQaasV1Alpha1Platform]:
57+
response = list_platforms_sync(client=self.__client, name=name)
58+
59+
assert response
60+
61+
return response.platforms
62+
63+
def create_session(
64+
self,
65+
name: str,
66+
platform_id: str,
67+
deduplication_id: str,
68+
max_duration: str,
69+
max_idle_duration: str,
70+
) -> ScalewayQaasV1Alpha1Session:
71+
session = create_session_sync(
72+
client=self.__client,
73+
body=CreateSessionBody(
74+
project_id=self.__project_id,
75+
name=name,
76+
platform_id=platform_id,
77+
deduplication_id=deduplication_id,
78+
max_duration=max_duration,
79+
max_idle_duration=max_idle_duration,
80+
),
81+
)
82+
83+
return session
84+
85+
def terminate_session(self, session_id: str) -> ScalewayQaasV1Alpha1Session:
86+
session = terminate_session_sync(
87+
client=self.__client,
88+
body=TerminateSessionBody(
89+
session_id=session_id,
90+
),
91+
)
92+
93+
return session
94+
95+
def delete_session(self, session_id: str):
96+
delete_session_sync(client=self.__client, session_id=session_id)
97+
98+
def create_job(
99+
self, name: str, session_id: str, circuits: Dict
100+
) -> ScalewayQaasV1Alpha1Job:
101+
circuits = circuits if isinstance(circuits, str) else json.dumps(circuits)
102+
103+
job = create_job_sync(
104+
client=self.__client,
105+
body=CreateJobBody(
106+
name=name,
107+
session_id=session_id,
108+
circuit=CreateJobBodyCircuit(qiskit_circuit=circuits),
109+
),
110+
)
111+
112+
return job
113+
114+
def get_job(self, job_id: str) -> ScalewayQaasV1Alpha1Job:
115+
job = get_job_sync(client=self.__client, job_id=job_id)
116+
117+
return job
118+
119+
def list_job_results(self, job_id: str) -> List[ScalewayQaasV1Alpha1JobResult]:
120+
response = list_job_result_sync(client=self.__client, job_id=job_id)
121+
122+
return response.job_results
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""A client library for accessing Quantum as a Service API"""
2+
3+
from .client import AuthenticatedClient, Client
4+
5+
__all__ = (
6+
"AuthenticatedClient",
7+
"Client",
8+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains methods for accessing the API"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains endpoint functions for accessing the API"""
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
from http import HTTPStatus
2+
from typing import Any, Optional, Union
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.scaleway_qaas_v1_alpha_1_application import (
9+
ScalewayQaasV1Alpha1Application,
10+
)
11+
from ...types import Response
12+
13+
14+
def _get_kwargs(
15+
application_id: str,
16+
) -> dict[str, Any]:
17+
_kwargs: dict[str, Any] = {
18+
"method": "get",
19+
"url": f"/qaas/v1alpha1/applications/{application_id}",
20+
}
21+
22+
return _kwargs
23+
24+
25+
def _parse_response(
26+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
27+
) -> Optional[ScalewayQaasV1Alpha1Application]:
28+
if response.status_code == 200:
29+
response_200 = ScalewayQaasV1Alpha1Application.from_dict(response.json())
30+
31+
return response_200
32+
if client.raise_on_unexpected_status:
33+
raise errors.UnexpectedStatus(response.status_code, response.content)
34+
else:
35+
return None
36+
37+
38+
def _build_response(
39+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
40+
) -> Response[ScalewayQaasV1Alpha1Application]:
41+
return Response(
42+
status_code=HTTPStatus(response.status_code),
43+
content=response.content,
44+
headers=response.headers,
45+
parsed=_parse_response(client=client, response=response),
46+
)
47+
48+
49+
def sync_detailed(
50+
application_id: str,
51+
*,
52+
client: AuthenticatedClient,
53+
) -> Response[ScalewayQaasV1Alpha1Application]:
54+
"""Get application information
55+
56+
Retrieve information about the provided **applcation ID**, such as name, type and compatible
57+
platforms.
58+
59+
Args:
60+
application_id (str): Unique ID of the application.
61+
62+
Raises:
63+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
64+
httpx.TimeoutException: If the request takes longer than Client.timeout.
65+
66+
Returns:
67+
Response[ScalewayQaasV1Alpha1Application]
68+
"""
69+
70+
kwargs = _get_kwargs(
71+
application_id=application_id,
72+
)
73+
74+
response = client.get_httpx_client().request(
75+
**kwargs,
76+
)
77+
78+
return _build_response(client=client, response=response)
79+
80+
81+
def sync(
82+
application_id: str,
83+
*,
84+
client: AuthenticatedClient,
85+
) -> Optional[ScalewayQaasV1Alpha1Application]:
86+
"""Get application information
87+
88+
Retrieve information about the provided **applcation ID**, such as name, type and compatible
89+
platforms.
90+
91+
Args:
92+
application_id (str): Unique ID of the application.
93+
94+
Raises:
95+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
96+
httpx.TimeoutException: If the request takes longer than Client.timeout.
97+
98+
Returns:
99+
ScalewayQaasV1Alpha1Application
100+
"""
101+
102+
return sync_detailed(
103+
application_id=application_id,
104+
client=client,
105+
).parsed
106+
107+
108+
async def asyncio_detailed(
109+
application_id: str,
110+
*,
111+
client: AuthenticatedClient,
112+
) -> Response[ScalewayQaasV1Alpha1Application]:
113+
"""Get application information
114+
115+
Retrieve information about the provided **applcation ID**, such as name, type and compatible
116+
platforms.
117+
118+
Args:
119+
application_id (str): Unique ID of the application.
120+
121+
Raises:
122+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
123+
httpx.TimeoutException: If the request takes longer than Client.timeout.
124+
125+
Returns:
126+
Response[ScalewayQaasV1Alpha1Application]
127+
"""
128+
129+
kwargs = _get_kwargs(
130+
application_id=application_id,
131+
)
132+
133+
response = await client.get_async_httpx_client().request(**kwargs)
134+
135+
return _build_response(client=client, response=response)
136+
137+
138+
async def asyncio(
139+
application_id: str,
140+
*,
141+
client: AuthenticatedClient,
142+
) -> Optional[ScalewayQaasV1Alpha1Application]:
143+
"""Get application information
144+
145+
Retrieve information about the provided **applcation ID**, such as name, type and compatible
146+
platforms.
147+
148+
Args:
149+
application_id (str): Unique ID of the application.
150+
151+
Raises:
152+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
153+
httpx.TimeoutException: If the request takes longer than Client.timeout.
154+
155+
Returns:
156+
ScalewayQaasV1Alpha1Application
157+
"""
158+
159+
return (
160+
await asyncio_detailed(
161+
application_id=application_id,
162+
client=client,
163+
)
164+
).parsed

0 commit comments

Comments
 (0)