aas-http-client 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl

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.

Potentially problematic release.


This version of aas-http-client might be problematic. Click here for more details.

@@ -0,0 +1,272 @@
1
+ """BaSyx Server interface for REST API communication."""
2
+
3
+ import json
4
+ import logging
5
+ from pathlib import Path
6
+
7
+ import basyx.aas.adapter.json
8
+
9
+ from basyx.aas.model import AssetAdministrationShell, Reference, Submodel
10
+ from aas_http_client.client import AasHttpClient, _create_client
11
+ logger = logging.getLogger(__name__)
12
+
13
+ class SdkWrapper():
14
+ """Represents a SdkWrapper to communicate with a REST API."""
15
+ _client: AasHttpClient = None
16
+
17
+ def post_shells(self, aas: AssetAdministrationShell) -> dict | None:
18
+ """Post an Asset Administration Shell (AAS) to the REST API.
19
+
20
+ :param aas: Asset Administration Shell to post
21
+ :return: Response data as a dictionary or None if an error occurred
22
+ """
23
+ aas_data_string = json.dumps(aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
24
+ aas_data = json.loads(aas_data_string)
25
+
26
+ return self._client.post_shells(aas_data)
27
+
28
+ def put_shells(self, identifier: str, aas: AssetAdministrationShell) -> bool:
29
+ """Update an Asset Administration Shell (AAS) by its ID in the REST API.
30
+
31
+ :param identifier: Identifier of the AAS to update
32
+ :param aas: Asset Administration Shell data to update
33
+ :return: True if the update was successful, False otherwise
34
+ """
35
+ aas_data_string = json.dumps(aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
36
+ aas_data = json.loads(aas_data_string)
37
+
38
+ return self._client.put_shells(identifier, aas_data)
39
+
40
+ def put_shells_submodels(self, aas_id: str, submodel_id: str, submodel: Submodel) -> bool:
41
+ """Update a submodel by its ID for a specific Asset Administration Shell (AAS).
42
+
43
+ :param aas_id: ID of the AAS to update the submodel for
44
+ :param submodel: Submodel data to update
45
+ :return: True if the update was successful, False otherwise
46
+ """
47
+ sm_data_string = json.dumps(submodel, cls=basyx.aas.adapter.json.AASToJsonEncoder)
48
+ sm_data = json.loads(sm_data_string)
49
+
50
+ return self._client.put_shells_submodels(aas_id, submodel_id, sm_data)
51
+
52
+ def get_shells(self) -> list[AssetAdministrationShell] | None:
53
+ """Get all Asset Administration Shells (AAS) from the REST API.
54
+
55
+ :return: AAS objects or None if an error occurred
56
+ """
57
+ content: dict = self._client.get_shells()
58
+
59
+ if not content:
60
+ logger.warning("No AAS found in the REST API.")
61
+ return []
62
+
63
+ results: list = content.get("result", [])
64
+ if not results:
65
+ logger.warning("No AAS found in the REST API results.")
66
+ return []
67
+
68
+ aas_list: list[AssetAdministrationShell] = []
69
+
70
+ for result in results:
71
+ if not isinstance(result, dict):
72
+ logger.error(f"Invalid AAS data: {result}")
73
+ return None
74
+
75
+ aas_dict_string = json.dumps(result)
76
+ aas = json.loads(aas_dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
77
+ aas_list.append(aas)
78
+
79
+ return aas_list
80
+
81
+ def get_shells_by_id(self, aas_id: str) -> AssetAdministrationShell | None:
82
+ """Get an Asset Administration Shell (AAS) by its ID from the REST API.
83
+
84
+ :param aas_id: ID of the AAS to retrieve
85
+ :return: AAS object or None if an error occurred
86
+ """
87
+ content: dict = self._client.get_shells_by_id(aas_id)
88
+ return json.load(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
89
+
90
+ def get_shells_reference_by_id(self, aas_id: str) -> Reference | None:
91
+ content: dict = self._client.get_shells_reference_by_id(aas_id)
92
+ return json.load(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
93
+
94
+ def get_shells_submodels(self, aas_id: str, submodel_id: str) -> Submodel | None:
95
+ """Get a submodel by its ID for a specific Asset Administration Shell (AAS).
96
+
97
+ :param aas_id: ID of the AAS to retrieve the submodel from
98
+ :param submodel_id: ID of the submodel to retrieve
99
+ :return: Submodel object or None if an error occurred
100
+ """
101
+ content: dict = self._client.get_shells_by_id(aas_id)
102
+ return json.load(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
103
+
104
+ def delete_shells_by_id(self, aas_id: str) -> bool:
105
+ """Get an Asset Administration Shell (AAS) by its ID from the REST API.
106
+
107
+ :param aas_id: ID of the AAS to retrieve
108
+ :return: True if the deletion was successful, False otherwise
109
+ """
110
+ return self._client.delete_shells_by_id(aas_id)
111
+
112
+ def post_submodels(self, submodel: Submodel) -> bool:
113
+ """Post a submodel to the REST API.
114
+
115
+ :param submodel: submodel data as a dictionary
116
+ :return: Response data as a dictionary or None if an error occurred
117
+ """
118
+ sm_data_string = json.dumps(submodel, cls=basyx.aas.adapter.json.AASToJsonEncoder)
119
+ sm_data = json.loads(sm_data_string)
120
+
121
+ return self._client.post_submodels(sm_data)
122
+
123
+ def put_submodels(self, identifier: str, submodel: Submodel) -> bool:
124
+ """Update a submodel by its ID in the REST API.
125
+
126
+ :param identifier: Identifier of the submodel to update
127
+ :param submodel: Submodel data to update
128
+ :return: True if the update was successful, False otherwise
129
+ """
130
+ sm_data_string = json.dumps(submodel, cls=basyx.aas.adapter.json.AASToJsonEncoder)
131
+ sm_data = json.loads(sm_data_string)
132
+
133
+ return self._client.put_submodels(identifier, sm_data)
134
+
135
+ def get_submodel_by_id(self, submodel_id: str) -> Submodel | None:
136
+ """Get a submodel by its ID from the REST API.
137
+
138
+ :param submodel_id: ID of the submodel to retrieve
139
+ :return: Submodel object or None if an error occurred
140
+ """
141
+ content = self._client.get_submodel_by_id(submodel_id)
142
+
143
+ if not content:
144
+ logger.warning(f"No submodel found with ID '{submodel_id}' in the REST API.")
145
+ return None
146
+
147
+ if not isinstance(content, dict):
148
+ logger.error(f"Invalid submodel data: {content}")
149
+ return None
150
+
151
+ return json.loads(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
152
+
153
+ def get_submodels(self) -> list[Submodel] | None:
154
+ """Get all submodels from the REST API.
155
+
156
+ :return: Submodel objects or None if an error occurred
157
+ """
158
+ content: list = self._client.get_submodels()
159
+
160
+ if not content:
161
+ logger.warning("No submodels found in the REST API.")
162
+ return []
163
+
164
+ results: list = content.get("result", [])
165
+ if not results:
166
+ logger.warning("No submodels found in the REST API results.")
167
+ return []
168
+
169
+ submodels: list[Submodel] = []
170
+
171
+ for result in results:
172
+ if not isinstance(result, dict):
173
+ logger.error(f"Invalid submodel data: {result}")
174
+ return None
175
+
176
+ sm_dict_string = json.dumps(result)
177
+ submodel = json.loads(sm_dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
178
+ submodels.append(submodel)
179
+
180
+ return submodels
181
+
182
+ def get_submodels_by_id(self, submodel_id: str) -> Submodel | None:
183
+ """Get a submodel by its ID from the REST API.
184
+
185
+ :param submodel_id: ID of the submodel to retrieve
186
+ :return: Submodel object or None if an error occurred
187
+ """
188
+ content = self._client.get_submodels_by_id(submodel_id)
189
+
190
+ if not content:
191
+ logger.warning(f"No submodel found with ID '{submodel_id}' in the REST API.")
192
+ return None
193
+
194
+ if not isinstance(content, dict):
195
+ logger.error(f"Invalid submodel data: {content}")
196
+ return None
197
+ #
198
+ return json.loads(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
199
+
200
+ def patch_submodel_by_id(self, submodel_id: str, submodel: Submodel):
201
+ sm_dict_string = json.dumps(submodel, cls=basyx.aas.adapter.json.AASToJsonEncoder)
202
+ sm_dict = json.loads(sm_dict_string)
203
+
204
+ return self._client.patch_submodel_by_id(submodel_id, sm_dict)
205
+
206
+ def delete_submodels_by_id(self, submodel_id: str) -> bool:
207
+ """Delete a submodel by its ID from the REST API.
208
+
209
+ :param submodel_id: ID of the submodel to delete
210
+ :return: True if the deletion was successful, False otherwise
211
+ """
212
+ return self._client.delete_submodels_by_id(submodel_id)
213
+
214
+ def create_wrapper_by_url(
215
+ base_url: str,
216
+ api_base_path: str = "",
217
+ username: str = "",
218
+ password: str = "",
219
+ http_proxy: str = "",
220
+ https_proxy: str = "",
221
+ time_out: int = 200,
222
+ connection_time_out: int = 60,
223
+ ssl_verify: str = True, # noqa: FBT002
224
+ ) -> SdkWrapper | None:
225
+ """Create a BaSyx server interface client from the given parameters.
226
+
227
+ :param base_url: base URL of the BaSyx server, e.g. "http://basyx_python_server:80/"_
228
+ :param username: username for the BaSyx server interface client, defaults to ""_
229
+ :param password: password for the BaSyx server interface client, defaults to ""_
230
+ :param http_proxy: http proxy URL, defaults to ""_
231
+ :param https_proxy: https proxy URL, defaults to ""_
232
+ :param time_out: timeout for the API calls, defaults to 200
233
+ :param connection_time_out: timeout for the connection to the API, defaults to 60
234
+ :param ssl_verify: whether to verify SSL certificates, defaults to True
235
+ :return: An instance of HttpClient initialized with the provided parameters.
236
+ """
237
+ logger.info(f"Create BaSyx server interface client from URL '{base_url}'")
238
+ config_dict: dict[str, str] = {}
239
+ config_dict["base_url"] = base_url
240
+ config_dict["api_base_path"] = api_base_path
241
+ config_dict["username"] = username
242
+ config_dict["http_proxy"] = http_proxy
243
+ config_dict["https_proxy"] = https_proxy
244
+ config_dict["time_out"] = time_out
245
+ config_dict["connection_time_out"] = connection_time_out
246
+ config_dict["ssl_verify"] = ssl_verify
247
+ config_string = json.dumps(config_dict, indent=4)
248
+
249
+ wrapper = SdkWrapper()
250
+ wrapper._client = _create_client(config_string, password)
251
+ return wrapper
252
+
253
+
254
+
255
+ def create_wrapper_by_config(config_file: Path, password: str = "") -> AasHttpClient | None:
256
+ """Create a BaSyx server interface client from the given parameters.
257
+
258
+ :param config_file: Path to the configuration file containing the BaSyx server connection settings.
259
+ :param password: password for the BaSyx server interface client, defaults to ""_
260
+ :return: An instance of HttpClient initialized with the provided parameters.
261
+ """
262
+ logger.info(f"Create BaSyx server interface client from config file '{config_file}'")
263
+ if not config_file.exists():
264
+ config_string = "{}"
265
+ logger.warning(f"Server config file '{config_file}' not found. Using default config.")
266
+ else:
267
+ config_string = config_file.read_text(encoding="utf-8")
268
+ logger.debug(f"Server config file '{config_file}' found.")
269
+
270
+ wrapper = SdkWrapper()
271
+ wrapper._client = _create_client(config_string, password)
272
+ return wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Generic HTTP client for communicating with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: MIT License
@@ -0,0 +1,15 @@
1
+ aas_http_client/__init__.py,sha256=M9EBVZcs0jg7v0RaziftjGcOzNET8gsgJ_-oRXNZxDo,657
2
+ aas_http_client/client.py,sha256=3I29OJJUPd2tP_46dDntyvzAlcFQHrMD2iEfc_mpn2I,21428
3
+ aas_http_client/core/encoder.py,sha256=FS7P0FPakzFsGz70eRFDHQZFA_2nlKLlWIxavtnFrPg,660
4
+ aas_http_client/core/version_check.py,sha256=721Zs3xSRrJTYZtAxkaUWg9LLKtpU7oFM62DzQHZdE4,705
5
+ aas_http_client/demo/demo_process.py,sha256=-9-oQEi_B08W-POl2SVP4COodGPHN3mTw9rrPgLLpeY,2170
6
+ aas_http_client/demo/logging_handler.py,sha256=VJtZ4u3x_LhYZQtfNck7FuXhGFZm7gid0uDhvf9GjJ8,5596
7
+ aas_http_client/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ aas_http_client/utilities/model_builder.py,sha256=bDK9cOrU4vlkQTHTgmeiVftQduKSZSKGAX10weSHQWs,3756
9
+ aas_http_client/wrapper/python_sdk_wrapper_tmp.py,sha256=J1ze7TXKMiOjA5dDVNrc-GRoxQ_9r7rU8qW8C0yErG0,24206
10
+ aas_http_client/wrapper/sdk_wrapper.py,sha256=sUfdawn9TWNbs7YELBTuMKBhiqd_eeQwk-AmzPWgLII,11117
11
+ aas_http_client-0.1.5.dist-info/licenses/LICENSE,sha256=simqYMD2P9Ikm0Kh9n7VGNpaVcm2TMVVQmECYZ_xVZ8,1065
12
+ aas_http_client-0.1.5.dist-info/METADATA,sha256=0W3KjbyhUkX7Pva9H8Mgl5dhgPl-r7Yce3ni_6w5ajI,2754
13
+ aas_http_client-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ aas_http_client-0.1.5.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
15
+ aas_http_client-0.1.5.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- aas_http_client/__init__.py,sha256=rB1C7XD-5BYvgx7HanHekZxgYxePk8hOB4EFSbaLjy0,470
2
- aas_http_client/client.py,sha256=MYLOedeslxw2Seyxd_zon87ryCosifiFOu8WJ7zcBGU,24190
3
- aas_http_client/core/encoder.py,sha256=FS7P0FPakzFsGz70eRFDHQZFA_2nlKLlWIxavtnFrPg,660
4
- aas_http_client-0.1.3.dist-info/licenses/LICENSE,sha256=simqYMD2P9Ikm0Kh9n7VGNpaVcm2TMVVQmECYZ_xVZ8,1065
5
- aas_http_client-0.1.3.dist-info/METADATA,sha256=20IKKrib_BEHGL5PwwJMY0THlDh1UX-atrJ3ohFFUbo,2754
6
- aas_http_client-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- aas_http_client-0.1.3.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
8
- aas_http_client-0.1.3.dist-info/RECORD,,