aas-http-client 0.2.3__py3-none-any.whl → 0.2.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.

aas_http_client/client.py CHANGED
@@ -121,8 +121,10 @@ class AasHttpClient(BaseModel):
121
121
  content = response.content.decode("utf-8")
122
122
  return json.loads(content)
123
123
 
124
- def post_shells(self, aas_data: dict) -> dict | None:
125
- """Post an Asset Administration Shell (AAS) to the REST API.
124
+ # region shells
125
+
126
+ def post_asset_administration_shell(self, aas_data: dict) -> dict | None:
127
+ """Creates a new Asset Administration Shell.
126
128
 
127
129
  :param aas_data: Json data of the Asset Administration Shell to post
128
130
  :return: Response data as a dictionary or None if an error occurred
@@ -145,8 +147,8 @@ class AasHttpClient(BaseModel):
145
147
  content = response.content.decode("utf-8")
146
148
  return json.loads(content)
147
149
 
148
- def put_shells(self, identifier: str, aas_data: dict) -> bool:
149
- """Update an Asset Administration Shell (AAS) by its ID in the REST API.
150
+ def put_asset_administration_shell_by_id(self, identifier: str, aas_data: dict) -> bool:
151
+ """Creates or replaces an existing Asset Administration Shell.
150
152
 
151
153
  :param identifier: Identifier of the AAS to update
152
154
  :param aas_data: Json data of the Asset Administration Shell data to update
@@ -169,8 +171,8 @@ class AasHttpClient(BaseModel):
169
171
 
170
172
  return True
171
173
 
172
- def put_shells_submodels_by_id(self, aas_id: str, submodel_id: str, submodel_data: dict) -> bool:
173
- """Update a submodel by its ID for a specific Asset Administration Shell (AAS).
174
+ def put_submodel_by_id_aas_repository(self, aas_id: str, submodel_id: str, submodel_data: dict) -> bool:
175
+ """Updates the Submodel.
174
176
 
175
177
  :param aas_id: ID of the AAS to update the submodel for
176
178
  :param submodel_data: Json data to the Submodel to update
@@ -194,8 +196,8 @@ class AasHttpClient(BaseModel):
194
196
 
195
197
  return True
196
198
 
197
- def get_shells(self) -> list[dict] | None:
198
- """Get all Asset Administration Shells (AAS) from the REST API.
199
+ def get_all_asset_administration_shells(self) -> list[dict] | None:
200
+ """Returns all Asset Administration Shells.
199
201
 
200
202
  :return: List of paginated Asset Administration Shells data or None if an error occurred
201
203
  """
@@ -216,8 +218,8 @@ class AasHttpClient(BaseModel):
216
218
  content = response.content.decode("utf-8")
217
219
  return json.loads(content)
218
220
 
219
- def get_shells_by_id(self, aas_id: str) -> dict | None:
220
- """Get an Asset Administration Shell (AAS) by its ID from the REST API.
221
+ def get_asset_administration_shell_by_id(self, aas_id: str) -> dict | None:
222
+ """Returns a specific Asset Administration Shell.
221
223
 
222
224
  :param aas_id: ID of the AAS to retrieve
223
225
  :return: Asset Administration Shells data or None if an error occurred
@@ -241,7 +243,12 @@ class AasHttpClient(BaseModel):
241
243
  return json.loads(content)
242
244
 
243
245
 
244
- def get_shells_reference_by_id(self, aas_id: str) -> Reference | None:
246
+ def get_asset_administration_shell_by_id_reference_aas_repository(self, aas_id: str) -> Reference | None:
247
+ """Returns a specific Asset Administration Shell as a Reference.
248
+
249
+ :param aas_id: ID of the AAS reference to retrieve
250
+ :return: Asset Administration Shells reference data or None if an error occurred
251
+ """
245
252
  decoded_aas_id: str = decode_base_64(aas_id)
246
253
  url = f"{self.base_url}/shells/{decoded_aas_id}/$reference"
247
254
 
@@ -260,8 +267,8 @@ class AasHttpClient(BaseModel):
260
267
  ref_dict_string = response.content.decode("utf-8")
261
268
  return json.loads(ref_dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
262
269
 
263
- def get_shells_submodels_by_id(self, aas_id: str, submodel_id: str) -> Submodel | None:
264
- """Get a submodel by its ID for a specific Asset Administration Shell (AAS).
270
+ def get_submodel_by_id_aas_repository(self, aas_id: str, submodel_id: str) -> Submodel | None:
271
+ """Returns the Submodel.
265
272
 
266
273
  :param aas_id: ID of the AAS to retrieve the submodel from
267
274
  :param submodel_id: ID of the submodel to retrieve
@@ -288,8 +295,8 @@ class AasHttpClient(BaseModel):
288
295
  content = response.content.decode("utf-8")
289
296
  return json.loads(content)
290
297
 
291
- def delete_shells_by_id(self, aas_id: str) -> bool:
292
- """Get an Asset Administration Shell (AAS) by its ID from the REST API.
298
+ def delete_asset_administration_shell_by_id(self, aas_id: str) -> bool:
299
+ """Deletes an Asset Administration Shell.
293
300
 
294
301
  :param aas_id: ID of the AAS to retrieve
295
302
  :return: True if the deletion was successful, False otherwise
@@ -311,11 +318,15 @@ class AasHttpClient(BaseModel):
311
318
 
312
319
  return True
313
320
 
314
- def post_submodels(self, submodel_data: dict) -> dict:
315
- """Post a submodel to the REST API.
321
+ # endregion
316
322
 
317
- :param submodel_data: Json data of the Submodel to post
318
- :return: Response data as a dictionary or None if an error occurred
323
+ # region submodels
324
+
325
+ def post_submodel(self, submodel_data: dict) -> dict | None:
326
+ """Creates a new Submodel.
327
+
328
+ :param Submodel_data: Json data of the Submodel to post
329
+ :return: Submodel data or None if an error occurred
319
330
  """
320
331
  url = f"{self.base_url}/submodels"
321
332
 
@@ -325,19 +336,19 @@ class AasHttpClient(BaseModel):
325
336
 
326
337
  if response.status_code not in (STATUS_CODE_201, STATUS_CODE_202):
327
338
  log_response_errors(response)
328
- return False
339
+ return None
329
340
 
330
341
  except requests.exceptions.RequestException as e:
331
342
  logger.error(f"Error call REST API: {e}")
332
- return False
343
+ return None
333
344
 
334
345
  content = response.content.decode("utf-8")
335
346
  return json.loads(content)
336
347
 
337
348
  def put_submodels_by_id(self, identifier: str, submodel_data: dict) -> bool:
338
- """Update a submodel by its ID in the REST API.
349
+ """Updates a existing Submodel.
339
350
 
340
- :param identifier: Identifier of the submodel to update
351
+ :param identifier: Encoded ID of the Submodel to update
341
352
  :param submodel_data: Json data of the Submodel to update
342
353
  :return: True if the update was successful, False otherwise
343
354
  """
@@ -358,10 +369,10 @@ class AasHttpClient(BaseModel):
358
369
 
359
370
  return True
360
371
 
361
- def get_submodels(self) -> list[dict] | None:
362
- """Get all submodels from the REST API.
372
+ def get_all_submodels(self) -> list[dict] | None:
373
+ """Returns all Submodels.
363
374
 
364
- :return: Submodel objects or None if an error occurred
375
+ :return: List of Submodel data or None if an error occurred
365
376
  """
366
377
  url = f"{self.base_url}/submodels"
367
378
 
@@ -380,11 +391,11 @@ class AasHttpClient(BaseModel):
380
391
  content = response.content.decode("utf-8")
381
392
  return json.loads(content)
382
393
 
383
- def get_submodels_by_id(self, submodel_id: str) -> dict | None:
384
- """Get a submodel by its ID from the REST API.
394
+ def get_submodel_by_id(self, submodel_id: str) -> dict | None:
395
+ """Returns a specific Submodel.
385
396
 
386
- :param submodel_id: ID of the submodel to retrieve
387
- :return: Submodel object or None if an error occurred
397
+ :param submodel_id: Encoded ID of the Submodel to retrieve
398
+ :return: Submodel data or None if an error occurred
388
399
  """
389
400
  decoded_submodel_id: str = decode_base_64(submodel_id)
390
401
  url = f"{self.base_url}/submodels/{decoded_submodel_id}"
@@ -404,7 +415,12 @@ class AasHttpClient(BaseModel):
404
415
  content = response.content.decode("utf-8")
405
416
  return json.loads(content)
406
417
 
407
- def patch_submodel_by_id(self, submodel_id: str, submodel_data: dict):
418
+ def patch_submodel_by_id(self, submodel_id: str, submodel_data: dict) -> bool:
419
+ """Updates an existing Submodel.
420
+
421
+ :param submodel_id: Encoded ID of the Submodel to delete
422
+ :return: True if the patch was successful, False otherwise
423
+ """
408
424
  decoded_submodel_id: str = decode_base_64(submodel_id)
409
425
  url = f"{self.base_url}/submodels/{decoded_submodel_id}"
410
426
 
@@ -422,10 +438,10 @@ class AasHttpClient(BaseModel):
422
438
 
423
439
  return True
424
440
 
425
- def delete_submodels_by_id(self, submodel_id: str) -> bool:
426
- """Delete a submodel by its ID from the REST API.
441
+ def delete_submodel_by_id(self, submodel_id: str) -> bool:
442
+ """Deletes a Submodel.
427
443
 
428
- :param submodel_id: ID of the submodel to delete
444
+ :param submodel_id: Encoded ID of the Submodel to delete
429
445
  :return: True if the deletion was successful, False otherwise
430
446
  """
431
447
  decoded_submodel_id: str = decode_base_64(submodel_id)
@@ -445,6 +461,57 @@ class AasHttpClient(BaseModel):
445
461
 
446
462
  return True
447
463
 
464
+ def get_all_submodel_elements_submodel_repository(self, submodel_id: str) -> list[dict] | None:
465
+ """Returns all submodel elements including their hierarchy.
466
+
467
+ :param submodel_id: Encoded ID of the Submodel to retrieve elements from
468
+ :return: List of Submodel element data or None if an error occurred
469
+ """
470
+ decoded_submodel_id: str = decode_base_64(submodel_id)
471
+ url = f"{self.base_url}/submodels/{decoded_submodel_id}/submodel-elements"
472
+
473
+ try:
474
+ response = self._session.get(url, headers=HEADERS, timeout=self.time_out)
475
+ logger.debug(f"Call REST API url '{response.url}'")
476
+
477
+ if response.status_code != STATUS_CODE_200:
478
+ log_response_errors(response)
479
+ return None
480
+
481
+ except requests.exceptions.RequestException as e:
482
+ logger.error(f"Error call REST API: {e}")
483
+ return None
484
+
485
+ content = response.content.decode("utf-8")
486
+ return json.loads(content)
487
+
488
+ def post_submodel_element_submodel_repo(self, submodel_id: str, submodel_element_data: dict) -> dict | None:
489
+ """Creates a new submodel element.
490
+
491
+ :param submodel_id: Encoded ID of the Submodel to create elements for
492
+ :return: Submodel element data or None if an error occurred
493
+ """
494
+ decoded_submodel_id: str = decode_base_64(submodel_id)
495
+ url = f"{self.base_url}/submodels/{decoded_submodel_id}/submodel-elements"
496
+
497
+ try:
498
+ response = self._session.post(url, headers=HEADERS, json=submodel_element_data, timeout=self.time_out)
499
+ logger.debug(f"Call REST API url '{response.url}'")
500
+
501
+ if response.status_code != STATUS_CODE_201:
502
+ log_response_errors(response)
503
+ return None
504
+
505
+ except requests.exceptions.RequestException as e:
506
+ logger.error(f"Error call REST API: {e}")
507
+ return None
508
+
509
+ content = response.content.decode("utf-8")
510
+ return json.loads(content)
511
+
512
+ # endregion
513
+
514
+ # region client
448
515
 
449
516
  def create_client_by_url(
450
517
  base_url: str,
@@ -480,7 +547,6 @@ def create_client_by_url(
480
547
  config_string = json.dumps(config_dict, indent=4)
481
548
  return _create_client(config_string, password)
482
549
 
483
-
484
550
  def create_client_by_config(config_file: Path, password: str = "") -> AasHttpClient | None:
485
551
  """Create a AAS HTTP client from the given parameters.
486
552
 
@@ -499,7 +565,6 @@ def create_client_by_config(config_file: Path, password: str = "") -> AasHttpCli
499
565
 
500
566
  return _create_client(config_string, password)
501
567
 
502
-
503
568
  def _create_client(config_string: str, password) -> AasHttpClient | None:
504
569
  try:
505
570
  connection_settings = AasHttpClient.model_validate_json(config_string)
@@ -525,7 +590,6 @@ def _create_client(config_string: str, password) -> AasHttpClient | None:
525
590
 
526
591
  return client
527
592
 
528
-
529
593
  def _connect_to_api(client: AasHttpClient) -> bool:
530
594
  start_time = time.time()
531
595
  logger.debug(f"Try to connect to REST API '{client.base_url}' for {client.connection_time_out} seconds")
@@ -544,3 +608,5 @@ def _connect_to_api(client: AasHttpClient) -> bool:
544
608
  counter += 1
545
609
  logger.warning(f"Retrying connection (attempt: {counter})")
546
610
  time.sleep(1)
611
+
612
+ # endregion
@@ -7,41 +7,52 @@ import json
7
7
  import basyx.aas.adapter.json
8
8
  import basyx.aas.model
9
9
 
10
+ from basyx.aas import model
11
+
10
12
  logger = logging.getLogger(__name__)
11
13
 
12
14
  def start():
13
15
  """Start the demo process."""
14
-
15
- aas_1 = _create_shell()
16
- aas_2 = _create_shell()
16
+ # create a submodel element
17
+ sme_short_id: str = model_builder.create_unique_short_id("poc_sme")
18
+ sme = model_builder.create_base_submodel_element_Property(sme_short_id, model.datatypes.String, "Sample Value")
17
19
 
18
- client = _create_client()
19
- java_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/java_server_config.json"))
20
- dotnet_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/dotnet_server_config.json"))
21
-
22
- java_sdk_wrapper.get_shells_by_id(aas_1.id)
23
- dotnet_sdk_wrapper.get_shells_by_id(aas_1.id)
20
+ # create a submodel
21
+ sm_short_id: str = model_builder.create_unique_short_id("poc_sm")
22
+ submodel = model_builder.create_base_submodel(sm_short_id)
23
+ # add submodel element to submodel
24
+ # submodel.submodel_element.add(sme)
24
25
 
25
- java_sdk_wrapper.get_submodels_by_id(aas_1.id)
26
- dotnet_sdk_wrapper.get_submodels_by_id(aas_1.id)
26
+ # create an AAS
27
+ aas_short_id: str = model_builder.create_unique_short_id("poc_aas")
28
+ aas = model_builder.create_base_ass(aas_short_id)
27
29
 
28
- exist_shells = java_sdk_wrapper.get_shells()
29
- exist_shells = dotnet_sdk_wrapper.get_shells()
30
+ # add submodel to AAS
31
+ model_builder.add_submodel_to_aas(aas, submodel)
30
32
 
31
- for shell in exist_shells:
32
- logger.warning(f"Delete shell '{shell.id}'")
33
- java_sdk_wrapper.delete_shells_by_id(shell.id)
33
+ java_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/java_server_config.json"))
34
+ # dotnet_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/dotnet_server_config.json"))
34
35
 
35
- java_sdk_wrapper.post_shells(aas_1)
36
+ for existing_shell in java_sdk_wrapper.get_all_asset_administration_shells():
37
+ logger.warning(f"Delete shell '{existing_shell.id}'")
38
+ java_sdk_wrapper.delete_asset_administration_shell_by_id(existing_shell.id)
36
39
 
40
+ for existing_submodel in java_sdk_wrapper.get_all_submodels():
41
+ logger.warning(f"Delete submodel '{existing_submodel.id}'")
42
+ java_sdk_wrapper.delete_submodel_by_id(existing_submodel.id)
37
43
 
38
- aas_dict_string = json.dumps(aas_2, cls=basyx.aas.adapter.json.AASToJsonEncoder)
39
- aas_dict = json.loads(aas_dict_string)
40
- client.post_shells(aas_dict)
41
-
42
- shells = client.get_shells()
44
+ java_sdk_wrapper.post_asset_administration_shell(aas)
45
+ java_sdk_wrapper.post_submodel(submodel)
46
+
47
+ tmp = java_sdk_wrapper.get_asset_administration_shell_by_id_reference_aas_repository(aas.id)
43
48
 
44
- logger.info(f"Client created successfully. {shells}")
49
+ shell = java_sdk_wrapper.get_asset_administration_shell_by_id(aas.id)
50
+ submodel = java_sdk_wrapper.get_submodel_by_id(submodel.id)
51
+
52
+ java_sdk_wrapper.post_submodel_element_submodel_repo(submodel.id, sme)
53
+
54
+ submodel = java_sdk_wrapper.get_submodel_by_id(submodel.id)
55
+
45
56
 
46
57
  def _create_shell() -> basyx.aas.model.AssetAdministrationShell:
47
58
  # create an AAS
@@ -57,11 +68,11 @@ def _create_shell() -> basyx.aas.model.AssetAdministrationShell:
57
68
 
58
69
  return aas
59
70
 
60
- def _create_client() -> AasHttpClient:
71
+ def _create_client(config: Path) -> AasHttpClient:
61
72
  """Create client for java servers."""
62
73
 
63
74
  try:
64
- file = Path("./aas_http_client/demo/java_server_config.json")
75
+ file = config
65
76
  client = create_client_by_config(file, password="")
66
77
  except Exception as e:
67
78
  logger.error(f"Failed to create client for {file}: {e}")
@@ -5,15 +5,8 @@ Provides some helper methods for easier work with basyx sdk data model
5
5
 
6
6
  import uuid
7
7
 
8
- from basyx.aas.model import (
9
- AssetAdministrationShell,
10
- AssetInformation,
11
- AssetKind,
12
- ModelReference,
13
- MultiLanguageTextType,
14
- Submodel,
15
- )
16
-
8
+ from basyx.aas import model
9
+ from typing import Any
17
10
 
18
11
  def create_unique_short_id(id_short: str) -> str:
19
12
  """Generate a unique identifier string by appending a UUID to the provided ID short.
@@ -23,8 +16,29 @@ def create_unique_short_id(id_short: str) -> str:
23
16
  """
24
17
  return f"{id_short}_{str(uuid.uuid4()).replace('-', '_')}"
25
18
 
19
+ def create_base_submodel_element_Property(id_short: str, type: model.datatypes, value: Any, display_name: str = "", description: str = "") -> model.Property:
20
+ """Create a basic Property Submodel Element.
21
+ """
22
+ sme = model.Property(
23
+ id_short=id_short,
24
+ value_type=type,
25
+ value=value)
26
+
27
+ if not description:
28
+ description = f"This is the submodel element with ID short '{id_short}'"
29
+
30
+ description_text = {"en": f"{description}"}
31
+ sme.description = model.MultiLanguageTextType(description_text)
32
+
33
+ if not display_name:
34
+ display_name = "POC Submodel Element"
35
+
36
+ display_name_text = {"en": f"{display_name}"}
37
+ sme.display_name = model.MultiLanguageTextType(display_name_text)
38
+
39
+ return sme
26
40
 
27
- def create_base_submodel(id_short: str, namespace: str = "basyx_python_aas_server", display_name: str = "", description: str = "") -> Submodel:
41
+ def create_base_submodel(id_short: str, namespace: str = "basyx_python_aas_server", display_name: str = "", description: str = "") -> model.Submodel:
28
42
  """Create a basic Submodel.
29
43
 
30
44
  :param id_short: ID short of the Submodel
@@ -37,27 +51,27 @@ def create_base_submodel(id_short: str, namespace: str = "basyx_python_aas_serve
37
51
  identifier = f"{namespace}/{id_short}"
38
52
  else:
39
53
  identifier = id_short
40
- sm = Submodel(identifier)
54
+ sm = model.Submodel(identifier)
41
55
  sm.id_short = id_short
42
56
 
43
57
  if not description:
44
58
  description = f"This is the submodel with ID short '{id_short}'"
45
59
 
46
60
  description_text = {"en": f"{description}"}
47
- sm.description = MultiLanguageTextType(description_text)
61
+ sm.description = model.MultiLanguageTextType(description_text)
48
62
 
49
63
  if not display_name:
50
64
  display_name = "POC AAS"
51
65
 
52
66
  display_name_text = {"en": f"{display_name}"}
53
- sm.display_name = MultiLanguageTextType(display_name_text)
67
+ sm.display_name = model.MultiLanguageTextType(display_name_text)
54
68
 
55
69
  return sm
56
70
 
57
71
 
58
72
  def create_base_ass(
59
73
  id_short: str, namespace: str = "basyx_python_aas_server", display_name: str = "", description: str = ""
60
- ) -> AssetAdministrationShell:
74
+ ) -> model.AssetAdministrationShell:
61
75
  """Create a basic AAS.
62
76
 
63
77
  :param id_short: ID short of the AAS
@@ -68,35 +82,35 @@ def create_base_ass(
68
82
  """
69
83
  asset_info = create_base_asset_information(id_short, namespace)
70
84
 
71
- aas = AssetAdministrationShell(id_=asset_info.global_asset_id, asset_information=asset_info)
85
+ aas = model.AssetAdministrationShell(id_=asset_info.global_asset_id, asset_information=asset_info)
72
86
  aas.id_short = id_short
73
87
 
74
88
  if not description:
75
89
  description = f"This is the asset administration shell with ID short '{id_short}'"
76
90
 
77
91
  description_text = {"en": f"{description}"}
78
- aas.description = MultiLanguageTextType(description_text)
92
+ aas.description = model.MultiLanguageTextType(description_text)
79
93
 
80
94
  if not display_name:
81
95
  display_name = "POC AAS"
82
96
 
83
97
  display_name_text = {"en": f"{display_name}"}
84
- aas.display_name = MultiLanguageTextType(display_name_text)
98
+ aas.display_name = model.MultiLanguageTextType(display_name_text)
85
99
 
86
100
  return aas
87
101
 
88
102
 
89
- def add_submodel_to_aas(aas: AssetAdministrationShell, submodel: Submodel) -> None:
103
+ def add_submodel_to_aas(aas: model.AssetAdministrationShell, submodel: model.Submodel) -> None:
90
104
  """Add a given Submodel correctly to a provided AssetAdministrationShell.
91
105
 
92
106
  :param aas: provided AssetAdministrationShell to which the Submodel should be added
93
107
  :param submodel: given Submodel to add
94
108
  """
95
109
  # aas.submodel.add(submodel)
96
- aas.submodel.add(ModelReference.from_referable(submodel))
110
+ aas.submodel.add(model.ModelReference.from_referable(submodel))
97
111
 
98
112
 
99
- def create_base_asset_information(id_short: str, namespace: str = "basyx_python_aas_server") -> AssetInformation:
113
+ def create_base_asset_information(id_short: str, namespace: str = "basyx_python_aas_server") -> model.AssetInformation:
100
114
  """Return a basic AssetInformation instance.
101
115
 
102
116
  :param id_short: short ID of the AssetInformation
@@ -107,13 +121,13 @@ def create_base_asset_information(id_short: str, namespace: str = "basyx_python_
107
121
  identifier = f"{namespace}/{id_short}"
108
122
  else:
109
123
  identifier = id_short
110
- return AssetInformation(AssetKind.INSTANCE, identifier)
124
+ return model.AssetInformation(model.AssetKind.INSTANCE, identifier)
111
125
 
112
126
 
113
- def create_reference(id: str) -> ModelReference:
127
+ def create_reference(id: str) -> model.ModelReference:
114
128
  """Create a ModelReference.
115
129
 
116
130
  :param id: ID of the Submodel to reference
117
131
  :return: ModelReference instance
118
132
  """
119
- return ModelReference.from_referable(Submodel(id))
133
+ return model.ModelReference.from_referable(model.Submodel(id))
@@ -7,49 +7,53 @@ from typing import Any
7
7
 
8
8
  import basyx.aas.adapter.json
9
9
 
10
- from basyx.aas.model import AssetAdministrationShell, Reference, Submodel, ModelReference
10
+ from basyx.aas import model
11
11
  from aas_http_client.client import AasHttpClient, _create_client
12
12
  logger = logging.getLogger(__name__)
13
13
 
14
14
  class SdkWrapper():
15
15
  """Represents a wrapper for the BaSyx Python SDK to communicate with a REST API."""
16
- _client: AasHttpClient = None
16
+ _client: AasHttpClient = None
17
+ base_url: str = ""
17
18
 
18
- def post_shells(self, aas: AssetAdministrationShell) -> dict | None:
19
- """Post an Asset Administration Shell (AAS) to the REST API.
19
+ # region shells
20
+
21
+ def post_asset_administration_shell(self, aas: model.AssetAdministrationShell) -> model.AssetAdministrationShell | None:
22
+ """Creates a new Asset Administration Shell.
20
23
 
21
24
  :param aas: Asset Administration Shell to post
22
25
  :return: Response data as a dictionary or None if an error occurred
23
26
  """
24
27
  aas_data = _to_dict(aas)
25
- return self._client.post_shells(aas_data)
28
+ content: dict = self._client.post_asset_administration_shell(aas_data)
29
+ return _to_object(content)
26
30
 
27
- def put_shells(self, identifier: str, aas: AssetAdministrationShell) -> bool:
28
- """Update an Asset Administration Shell (AAS) by its ID in the REST API.
31
+ def put_asset_administration_shell_by_id(self, identifier: str, aas: model.AssetAdministrationShell) -> bool:
32
+ """Creates or replaces an existing Asset Administration Shell.
29
33
 
30
34
  :param identifier: Identifier of the AAS to update
31
35
  :param aas: Asset Administration Shell data to update
32
36
  :return: True if the update was successful, False otherwise
33
37
  """
34
38
  aas_data = _to_dict(aas)
35
- return self._client.put_shells(identifier, aas_data)
39
+ return self._client.put_asset_administration_shell_by_id(identifier, aas_data)
36
40
 
37
- def put_shells_submodels_by_id(self, aas_id: str, submodel_id: str, submodel: Submodel) -> bool:
38
- """Update a submodel by its ID for a specific Asset Administration Shell (AAS).
41
+ def put_submodel_by_id_aas_repository(self, aas_id: str, submodel_id: str, submodel: model.Submodel) -> bool:
42
+ """Updates the Submodel.
39
43
 
40
44
  :param aas_id: ID of the AAS to update the submodel for
41
45
  :param submodel: Submodel data to update
42
46
  :return: True if the update was successful, False otherwise
43
47
  """
44
48
  sm_data = _to_dict(submodel)
45
- return self._client.put_shells_submodels_by_id(aas_id, submodel_id, sm_data)
49
+ return self._client.put_submodel_by_id_aas_repository(aas_id, submodel_id, sm_data)
46
50
 
47
- def get_shells(self) -> list[AssetAdministrationShell] | None:
48
- """Get all Asset Administration Shells (AAS) from the REST API.
51
+ def get_all_asset_administration_shells(self) -> list[model.AssetAdministrationShell] | None:
52
+ """Returns all Asset Administration Shells.
49
53
 
50
- :return: AAS objects or None if an error occurred
54
+ :return: Asset Administration Shells objects or None if an error occurred
51
55
  """
52
- content: dict = self._client.get_shells()
56
+ content: dict = self._client.get_all_asset_administration_shells()
53
57
 
54
58
  if not content:
55
59
  return None
@@ -59,7 +63,7 @@ class SdkWrapper():
59
63
  logger.warning("No shells found on server.")
60
64
  return []
61
65
 
62
- aas_list: list[AssetAdministrationShell] = []
66
+ aas_list: list[model.AssetAdministrationShell] = []
63
67
 
64
68
  for result in results:
65
69
  if not isinstance(result, dict):
@@ -73,13 +77,13 @@ class SdkWrapper():
73
77
 
74
78
  return aas_list
75
79
 
76
- def get_shells_by_id(self, aas_id: str) -> AssetAdministrationShell | None:
77
- """Get an Asset Administration Shell (AAS) by its ID from the REST API.
78
-
80
+ def get_asset_administration_shell_by_id(self, aas_id: str) -> model.AssetAdministrationShell | None:
81
+ """Returns a specific Asset Administration Shell.
82
+
79
83
  :param aas_id: ID of the AAS to retrieve
80
- :return: AAS object or None if an error occurred
84
+ :return: Asset Administration Shells object or None if an error occurred
81
85
  """
82
- content: dict = self._client.get_shells_by_id(aas_id)
86
+ content: dict = self._client.get_asset_administration_shell_by_id(aas_id)
83
87
 
84
88
  if not content:
85
89
  logger.warning(f"No shell found with ID '{aas_id}' on server.")
@@ -87,43 +91,53 @@ class SdkWrapper():
87
91
 
88
92
  return _to_object(content)
89
93
 
90
- def get_shells_reference_by_id(self, aas_id: str) -> Reference | None:
94
+ def get_asset_administration_shell_by_id_reference_aas_repository(self, aas_id: str) -> model.Reference | None:
95
+ """Returns a specific Asset Administration Shell as a Reference.
96
+
97
+ :param aas_id: ID of the AAS reference to retrieve
98
+ :return: Asset Administration Shells reference object or None if an error occurred
99
+ """
91
100
  #workaround because serialization not working
92
- aas = self.get_shells_by_id(aas_id)
93
- return ModelReference.from_referable(aas)
101
+ aas = self.get_asset_administration_shell_by_id(aas_id)
102
+ return model.ModelReference.from_referable(aas)
94
103
 
95
104
  # content: dict = self._client.get_shells_reference_by_id(aas_id)
96
105
  # return json.loads(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
97
106
 
98
- def get_shells_submodels_by_id(self, aas_id: str, submodel_id: str) -> Submodel | None:
99
- """Get a submodel by its ID for a specific Asset Administration Shell (AAS).
107
+ def get_submodel_by_id_aas_repository(self, aas_id: str, submodel_id: str) -> model.Submodel | None:
108
+ """Returns the Submodel.
100
109
 
101
110
  :param aas_id: ID of the AAS to retrieve the submodel from
102
111
  :param submodel_id: ID of the submodel to retrieve
103
112
  :return: Submodel object or None if an error occurred
104
113
  """
105
- content: dict = self._client.get_shells_submodels_by_id(aas_id, submodel_id)
114
+ content: dict = self._client.get_submodel_by_id_aas_repository(aas_id, submodel_id)
106
115
  return _to_object(content)
107
116
 
108
- def delete_shells_by_id(self, aas_id: str) -> bool:
109
- """Get an Asset Administration Shell (AAS) by its ID from the REST API.
117
+ def delete_asset_administration_shell_by_id(self, aas_id: str) -> bool:
118
+ """Deletes an Asset Administration Shell.
110
119
 
111
120
  :param aas_id: ID of the AAS to retrieve
112
121
  :return: True if the deletion was successful, False otherwise
113
122
  """
114
- return self._client.delete_shells_by_id(aas_id)
123
+ return self._client.delete_asset_administration_shell_by_id(aas_id)
115
124
 
116
- def post_submodels(self, submodel: Submodel) -> bool:
117
- """Post a submodel to the REST API.
125
+ # endregion
126
+
127
+ # region submodels
128
+
129
+ def post_submodel(self, submodel: model.Submodel) -> model.Submodel | None:
130
+ """Creates a new Submodel.
118
131
 
119
132
  :param submodel: submodel data as a dictionary
120
133
  :return: Response data as a dictionary or None if an error occurred
121
134
  """
122
135
  sm_data = _to_dict(submodel)
123
- return self._client.post_submodels(sm_data)
136
+ content: dict = self._client.post_submodel(sm_data)
137
+ return _to_object(content)
124
138
 
125
- def put_submodels_by_id(self, identifier: str, submodel: Submodel) -> bool:
126
- """Update a submodel by its ID in the REST API.
139
+ def put_submodels_by_id(self, identifier: str, submodel: model.Submodel) -> bool:
140
+ """Updates a existing Submodel.
127
141
 
128
142
  :param identifier: Identifier of the submodel to update
129
143
  :param submodel: Submodel data to update
@@ -132,12 +146,12 @@ class SdkWrapper():
132
146
  sm_data = _to_dict(submodel)
133
147
  return self._client.put_submodels_by_id(identifier, sm_data)
134
148
 
135
- def get_submodels(self) -> list[Submodel] | None:
136
- """Get all submodels from the REST API.
149
+ def get_all_submodels(self) -> list[model.Submodel] | None:
150
+ """Returns all Submodels.
137
151
 
138
152
  :return: Submodel objects or None if an error occurred
139
153
  """
140
- content: list = self._client.get_submodels()
154
+ content: list = self._client.get_all_submodels()
141
155
 
142
156
  if not content:
143
157
  return []
@@ -147,7 +161,7 @@ class SdkWrapper():
147
161
  logger.warning("No submodels found on server.")
148
162
  return []
149
163
 
150
- submodels: list[Submodel] = []
164
+ submodels: list[model.Submodel] = []
151
165
 
152
166
  for result in results:
153
167
  if not isinstance(result, dict):
@@ -161,13 +175,13 @@ class SdkWrapper():
161
175
 
162
176
  return submodels
163
177
 
164
- def get_submodels_by_id(self, submodel_id: str) -> Submodel | None:
165
- """Get a submodel by its ID from the REST API.
178
+ def get_submodel_by_id(self, submodel_id: str) -> model.Submodel | None:
179
+ """Returns a specific Submodel.
166
180
 
167
181
  :param submodel_id: ID of the submodel to retrieve
168
182
  :return: Submodel object or None if an error occurred
169
183
  """
170
- content = self._client.get_submodels_by_id(submodel_id)
184
+ content = self._client.get_submodel_by_id(submodel_id)
171
185
 
172
186
  if not content:
173
187
  logger.warning(f"No submodel found with ID '{submodel_id}' on server.")
@@ -175,17 +189,68 @@ class SdkWrapper():
175
189
 
176
190
  return _to_object(content)
177
191
 
178
- def patch_submodel_by_id(self, submodel_id: str, submodel: Submodel):
192
+ def patch_submodel_by_id(self, submodel_id: str, submodel: model.Submodel):
193
+ """Updates an existing Submodel
194
+
195
+ :param submodel_id: Encoded ID of the Submodel to delete
196
+ :return: True if the patch was successful, False otherwise
197
+ """
179
198
  sm_data = _to_dict(submodel)
180
199
  return self._client.patch_submodel_by_id(submodel_id, sm_data)
181
200
 
182
- def delete_submodels_by_id(self, submodel_id: str) -> bool:
183
- """Delete a submodel by its ID from the REST API.
201
+ def delete_submodel_by_id(self, submodel_id: str) -> bool:
202
+ """Deletes a Submodel.
184
203
 
185
204
  :param submodel_id: ID of the submodel to delete
186
205
  :return: True if the deletion was successful, False otherwise
187
206
  """
188
- return self._client.delete_submodels_by_id(submodel_id)
207
+ return self._client.delete_submodel_by_id(submodel_id)
208
+
209
+ def get_all_submodel_elements_submodel_repository(self, submodel_id: str, ) -> list[model.SubmodelElement] | None:
210
+ """Returns all submodel elements including their hierarchy.
211
+ !!! Serialization to model.SubmodelElement currently not possible
212
+
213
+ :param submodel_id: Encoded ID of the Submodel to retrieve elements from
214
+ :return: List of Submodel elements or None if an error occurred
215
+ """
216
+ content = self._client.get_all_submodel_elements_submodel_repository(submodel_id)
217
+
218
+ if not content:
219
+ return []
220
+
221
+ results: list = content.get("result", [])
222
+ if not results:
223
+ logger.warning("No submodels found on server.")
224
+ return []
225
+
226
+ submodel_elements: list[model.SubmodelElement] = []
227
+
228
+ for result in results:
229
+ if not isinstance(result, dict):
230
+ logger.error(f"Invalid submodel data: {result}")
231
+ return None
232
+
233
+ submodel_element = _to_object(result)
234
+
235
+ if submodel_element:
236
+ submodel_elements.append(submodel_element)
237
+
238
+ return submodel_elements
239
+
240
+ def post_submodel_element_submodel_repo(self, submodel_id: str, submodel_element: model.SubmodelElement) -> model.SubmodelElement | None:
241
+ """Creates a new submodel element.
242
+ !!! Serialization to model.SubmodelElements currently not possible
243
+
244
+ :param submodel_id: Encoded ID of the submodel to create elements for
245
+ :param submodel_element: Submodel element to create
246
+ :return: List of submodel element objects or None if an error occurred
247
+ """
248
+ sme_data = _to_dict(submodel_element)
249
+ content: dict = self._client.post_submodel_element_submodel_repo(submodel_id, sme_data)
250
+ return _to_object(content)
251
+
252
+
253
+ # endregion
189
254
 
190
255
  def _to_object(content: dict) -> Any | None:
191
256
  try:
@@ -205,6 +270,8 @@ def _to_dict(object: Any) -> dict | None:
205
270
  logger.error(f"In object: {object}")
206
271
  return None
207
272
 
273
+ # region wrapper
274
+
208
275
  def create_wrapper_by_url(
209
276
  base_url: str,
210
277
  username: str = "",
@@ -244,11 +311,10 @@ def create_wrapper_by_url(
244
311
  if not client:
245
312
  return None
246
313
 
247
- wrapper._client = client
314
+ wrapper._client = client
315
+ wrapper.base_url = client.base_url
248
316
  return wrapper
249
317
 
250
-
251
-
252
318
  def create_wrapper_by_config(config_file: Path, password: str = "") -> SdkWrapper | None:
253
319
  """Create a wrapper for the BaSyx Python SDK from the given parameters.
254
320
 
@@ -270,5 +336,8 @@ def create_wrapper_by_config(config_file: Path, password: str = "") -> SdkWrappe
270
336
  if not client:
271
337
  return None
272
338
 
273
- wrapper._client = client
274
- return wrapper
339
+ wrapper._client = client
340
+ wrapper.base_url = client.base_url
341
+ return wrapper
342
+
343
+ # endregion
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -153,6 +153,8 @@ Wrappers are currently available for the following frameworks:
153
153
 
154
154
  🤖 [Releases](http://github.com/fluid40/aas-http-client/releases)
155
155
 
156
+ 📝 [Changelog](CHANGELOG.md)
157
+
156
158
  📦 [Pypi Packages](https://pypi.org/project/aas-http-client/)
157
159
 
158
160
  📜 [em AG Software License](LICENSE)
@@ -0,0 +1,14 @@
1
+ aas_http_client/__init__.py,sha256=cAr1mQzWp0G0LKtkAOYzc9t95OY3jM3Aj4bKnxx0Dso,901
2
+ aas_http_client/client.py,sha256=LEUh3cVZnOnqL37OQx3nrLaqqbMfROUnA47mv6Hrvz4,23118
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=Rutj6TAk9raCllSnfNYe2XODg_CrP_hBZMJPWEq93Yw,3374
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=mL06SX208dMJHpiB-ol51JA9Bm3czoI8ELYTfismCq8,4633
9
+ aas_http_client/wrapper/sdk_wrapper.py,sha256=aRoMY2SAkp9f1Yjz1ZhvpnUJi3jyG58qkUWZZA32iu4,13017
10
+ aas_http_client-0.2.5.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
11
+ aas_http_client-0.2.5.dist-info/METADATA,sha256=UpTC7_w415iC_JdPwrVjiFJullifwnzEBWtQ84p6urg,10333
12
+ aas_http_client-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ aas_http_client-0.2.5.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
14
+ aas_http_client-0.2.5.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- aas_http_client/__init__.py,sha256=cAr1mQzWp0G0LKtkAOYzc9t95OY3jM3Aj4bKnxx0Dso,901
2
- aas_http_client/client.py,sha256=6d3g9VNhex1JrZwIXtBTopSTw3bsf5NZBSWG5mHYuQg,20705
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=QfneAU2KXHUt90jEsOEx1VA4xgXW7PHsLsVVXI5BOgg,2602
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=bL4hy3uHh1Y_uL6KmLIfo9ORiUqWNlyToJrAt8G1rpw,3877
9
- aas_http_client/wrapper/sdk_wrapper.py,sha256=-0bKx5oP5jYosVAnuRlajMgJA1PJbOLLWm1j0fh1y_k,10334
10
- aas_http_client-0.2.3.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
11
- aas_http_client-0.2.3.dist-info/METADATA,sha256=9sTQ4BxzU1ZOFMG2UVjAIb_sGWD1grxZPKt4-VSPzlk,10301
12
- aas_http_client-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- aas_http_client-0.2.3.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
14
- aas_http_client-0.2.3.dist-info/RECORD,,