aas-http-client 0.3.5__tar.gz → 0.3.8__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.

Potentially problematic release.


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

Files changed (21) hide show
  1. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/PKG-INFO +1 -1
  2. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/client.py +10 -7
  3. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/core/version_check.py +4 -2
  4. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/demo/demo_process.py +1 -1
  5. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/utilities/model_builder.py +2 -12
  6. aas_http_client-0.3.8/aas_http_client/utilities/sdk_tools.py +50 -0
  7. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/wrapper/sdk_wrapper.py +8 -30
  8. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client.egg-info/PKG-INFO +1 -1
  9. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client.egg-info/SOURCES.txt +1 -0
  10. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/pyproject.toml +1 -1
  11. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/tests/test_client.py +6 -5
  12. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/tests/test_wrapper.py +6 -5
  13. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/LICENSE +0 -0
  14. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/README.md +0 -0
  15. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/__init__.py +0 -0
  16. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/core/encoder.py +0 -0
  17. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client/utilities/__init__.py +0 -0
  18. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client.egg-info/dependency_links.txt +0 -0
  19. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client.egg-info/requires.txt +0 -0
  20. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/aas_http_client.egg-info/top_level.txt +0 -0
  21. {aas_http_client-0.3.5 → aas_http_client-0.3.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.5
3
+ Version: 0.3.8
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
@@ -80,7 +80,7 @@ class AasHttpClient(BaseModel):
80
80
  time_out: int = 200
81
81
  connection_time_out: int = 100
82
82
  ssl_verify: bool = True
83
- trust_env: bool = False
83
+ trust_env: bool = True
84
84
  _session: Session = PrivateAttr(default=None)
85
85
 
86
86
  def initialize(self, password: str):
@@ -602,6 +602,7 @@ def create_client_by_url(
602
602
  time_out: int = 200,
603
603
  connection_time_out: int = 60,
604
604
  ssl_verify: str = True, # noqa: FBT002
605
+ trust_env: bool = True, # noqa: FBT001, FBT002
605
606
  ) -> AasHttpClient | None:
606
607
  """Create a HTTP client for a AAS server connection from the given parameters.
607
608
 
@@ -613,9 +614,10 @@ def create_client_by_url(
613
614
  :param time_out: Timeout for the API calls, defaults to 200
614
615
  :param connection_time_out: Timeout for the connection to the API, defaults to 60
615
616
  :param ssl_verify: Whether to verify SSL certificates, defaults to True
617
+ :param trust_env: Whether to trust environment variables for proxy settings, defaults to True
616
618
  :return: An instance of Http client initialized with the provided parameters.
617
619
  """
618
- logger.info(f"Create AAS server http client from URL '{base_url}'")
620
+ logger.info(f"Create AAS server http client from URL '{base_url}'.")
619
621
  config_dict: dict[str, str] = {}
620
622
  config_dict["base_url"] = base_url
621
623
  config_dict["username"] = username
@@ -624,6 +626,7 @@ def create_client_by_url(
624
626
  config_dict["time_out"] = time_out
625
627
  config_dict["connection_time_out"] = connection_time_out
626
628
  config_dict["ssl_verify"] = ssl_verify
629
+ config_dict["trust_env"] = trust_env
627
630
  return create_client_by_dict(config_dict, password)
628
631
 
629
632
 
@@ -634,7 +637,7 @@ def create_client_by_dict(configuration: dict, password: str = "") -> AasHttpCli
634
637
  :param password: Password for the AAS server, defaults to ""_
635
638
  :return: An instance of Http client initialized with the provided parameters.
636
639
  """
637
- logger.info(f"Create AAS server http client from configuration '{configuration}'")
640
+ logger.info("Create AAS server http client from dictionary.")
638
641
  config_string = json.dumps(configuration, indent=4)
639
642
 
640
643
  return _create_client(config_string, password)
@@ -648,7 +651,7 @@ def create_client_by_config(config_file: Path, password: str = "") -> AasHttpCli
648
651
  :return: An instance of Http client initialized with the provided parameters.
649
652
  """
650
653
  config_file = config_file.resolve()
651
- logger.info(f"Create AAS server http client from configuration file '{config_file}'")
654
+ logger.info(f"Create AAS server http client from configuration file '{config_file}'.")
652
655
  if not config_file.exists():
653
656
  config_string = "{}"
654
657
  logger.warning(f"Configuration file '{config_file}' not found. Using default configuration.")
@@ -671,7 +674,7 @@ def _create_client(config_string: str, password: str) -> AasHttpClient | None:
671
674
  f"username: '{client.username}' | "
672
675
  f"https_proxy: '{client.https_proxy}' | "
673
676
  f"http_proxy: '{client.http_proxy}' | "
674
- f"connection_timeout: '{client.connection_time_out}'"
677
+ f"connection_timeout: '{client.connection_time_out}'."
675
678
  )
676
679
  client.initialize(password)
677
680
 
@@ -686,7 +689,7 @@ def _create_client(config_string: str, password: str) -> AasHttpClient | None:
686
689
 
687
690
  def _connect_to_api(client: AasHttpClient) -> bool:
688
691
  start_time = time.time()
689
- logger.debug(f"Try to connect to REST API '{client.base_url}' for {client.connection_time_out} seconds")
692
+ logger.debug(f"Try to connect to REST API '{client.base_url}' for {client.connection_time_out} seconds.")
690
693
  counter: int = 0
691
694
  while True:
692
695
  try:
@@ -700,7 +703,7 @@ def _connect_to_api(client: AasHttpClient) -> bool:
700
703
  raise TimeoutError(f"Connection to server API timed out after {client.connection_time_out} seconds.")
701
704
 
702
705
  counter += 1
703
- logger.warning(f"Retrying connection (attempt: {counter})")
706
+ logger.warning(f"Retrying connection (attempt: {counter}).")
704
707
  time.sleep(1)
705
708
 
706
709
 
@@ -1,6 +1,8 @@
1
- import requests
2
1
  import importlib.metadata
3
2
 
3
+ import requests
4
+
5
+
4
6
  def check_for_update(package_name="aas-http-client"):
5
7
  try:
6
8
  current_version = importlib.metadata.version(package_name)
@@ -14,4 +16,4 @@ def check_for_update(package_name="aas-http-client"):
14
16
  f"Use the following command to update the package: pip install --upgrade {package_name}"
15
17
  )
16
18
  except Exception:
17
- pass
19
+ pass
@@ -16,7 +16,7 @@ def start() -> None:
16
16
  """Start the demo process."""
17
17
  # create a submodel element
18
18
  sme_short_id: str = model_builder.create_unique_short_id("poc_sme")
19
- sme = model_builder.create_base_submodel_element_Property(sme_short_id, model.datatypes.String, "Sample Value")
19
+ sme = model_builder.create_base_submodel_element_property(sme_short_id, model.datatypes.String, "Sample Value")
20
20
 
21
21
  # create a submodel
22
22
  sm_short_id: str = model_builder.create_unique_short_id("poc_sm")
@@ -18,10 +18,10 @@ def create_unique_short_id(id_short: str) -> str:
18
18
  return f"{id_short}_{str(uuid.uuid4()).replace('-', '_')}"
19
19
 
20
20
 
21
- def create_base_submodel_element_Property(
21
+ def create_base_submodel_element_property(
22
22
  id_short: str, type: model.datatypes, value: Any, display_name: str = "", description: str = ""
23
23
  ) -> model.Property:
24
- """Create a basic Property Submodel Element."""
24
+ """Create a basic SubmodelElement of type Property."""
25
25
  sme = model.Property(id_short=id_short, value_type=type, value=value)
26
26
 
27
27
  if not description:
@@ -97,16 +97,6 @@ def create_base_ass(id_short: str, namespace: str = "fluid40", display_name: str
97
97
  return aas
98
98
 
99
99
 
100
- def add_submodel_to_aas(aas: model.AssetAdministrationShell, submodel: model.Submodel) -> None:
101
- """Add a given Submodel correctly to a provided AssetAdministrationShell.
102
-
103
- :param aas: provided AssetAdministrationShell to which the Submodel should be added
104
- :param submodel: given Submodel to add
105
- """
106
- # aas.submodel.add(submodel)
107
- aas.submodel.add(model.ModelReference.from_referable(submodel))
108
-
109
-
110
100
  def create_base_asset_information(id_short: str, namespace: str = "basyx_python_aas_server") -> model.AssetInformation:
111
101
  """Return a basic AssetInformation instance.
112
102
 
@@ -0,0 +1,50 @@
1
+ """Utility functions for working with the BaSyx SDK framework objects."""
2
+
3
+ import json
4
+ import logging
5
+ from typing import Any
6
+
7
+ import basyx.aas.adapter.json
8
+ from basyx.aas import model
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ def add_submodel_to_aas(aas: model.AssetAdministrationShell, submodel: model.Submodel) -> None:
14
+ """Add a given Submodel correctly to a provided AssetAdministrationShell.
15
+
16
+ :param aas: provided AssetAdministrationShell to which the Submodel should be added
17
+ :param submodel: given Submodel to add
18
+ """
19
+ # aas.submodel.add(submodel)
20
+ aas.submodel.add(model.ModelReference.from_referable(submodel))
21
+
22
+
23
+ def convert_to_object(content: dict) -> Any | None:
24
+ """Convert a dictionary to a BaSyx SDK framework object.
25
+
26
+ :param content: dictionary to convert
27
+ :return: BaSyx SDK framework object or None
28
+ """
29
+ try:
30
+ dict_string = json.dumps(content)
31
+ return json.loads(dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
32
+ except Exception as e:
33
+ logger.error(f"Decoding error: {e}")
34
+ logger.error(f"In JSON: {content}")
35
+ return None
36
+
37
+
38
+ def convert_to_dict(object: Any) -> dict | None:
39
+ """Convert a BaSyx SDK framework object. to a dictionary.
40
+
41
+ :param object: BaSyx SDK framework object to convert
42
+ :return: dictionary representation of the object or None
43
+ """
44
+ try:
45
+ data_string = json.dumps(object, cls=basyx.aas.adapter.json.AASToJsonEncoder)
46
+ return json.loads(data_string)
47
+ except Exception as e:
48
+ logger.error(f"Encoding error: {e}")
49
+ logger.error(f"In object: {object}")
50
+ return None
@@ -3,12 +3,12 @@
3
3
  import json
4
4
  import logging
5
5
  from pathlib import Path
6
- from typing import Any
7
6
 
8
- import basyx.aas.adapter.json
9
7
  from basyx.aas import model
10
8
 
11
9
  from aas_http_client.client import AasHttpClient, _create_client
10
+ from aas_http_client.utilities.sdk_tools import convert_to_dict as _to_dict
11
+ from aas_http_client.utilities.sdk_tools import convert_to_object as _to_object
12
12
 
13
13
  logger = logging.getLogger(__name__)
14
14
 
@@ -298,31 +298,6 @@ class SdkWrapper:
298
298
  return self._client
299
299
 
300
300
 
301
- # region utils
302
-
303
-
304
- def _to_object(content: dict) -> Any | None:
305
- try:
306
- dict_string = json.dumps(content)
307
- return json.loads(dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
308
- except Exception as e:
309
- logger.error(f"Decoding error: {e}")
310
- logger.error(f"In JSON: {content}")
311
- return None
312
-
313
-
314
- def _to_dict(object: Any) -> dict | None:
315
- try:
316
- data_string = json.dumps(object, cls=basyx.aas.adapter.json.AASToJsonEncoder)
317
- return json.loads(data_string)
318
- except Exception as e:
319
- logger.error(f"Encoding error: {e}")
320
- logger.error(f"In object: {object}")
321
- return None
322
-
323
-
324
- # endregion
325
-
326
301
  # region wrapper
327
302
 
328
303
 
@@ -335,6 +310,7 @@ def create_wrapper_by_url(
335
310
  time_out: int = 200,
336
311
  connection_time_out: int = 60,
337
312
  ssl_verify: str = True, # noqa: FBT002
313
+ trust_env: bool = True, # noqa: FBT001, FBT002
338
314
  ) -> SdkWrapper | None:
339
315
  """Create a wrapper for a AAS server connection from the given parameters.
340
316
 
@@ -346,9 +322,10 @@ def create_wrapper_by_url(
346
322
  :param time_out: timeout for the API calls, defaults to 200
347
323
  :param connection_time_out: timeout for the connection to the API, defaults to 60
348
324
  :param ssl_verify: whether to verify SSL certificates, defaults to True
325
+ :param trust_env: Whether to trust environment variables for proxy settings, defaults to True
349
326
  :return: An instance of SdkWrapper initialized with the provided parameters.
350
327
  """
351
- logger.info(f"Create AAS server wrapper from URL '{base_url}'")
328
+ logger.info(f"Create AAS server wrapper from URL '{base_url}'.")
352
329
  config_dict: dict[str, str] = {}
353
330
  config_dict["base_url"] = base_url
354
331
  config_dict["username"] = username
@@ -357,6 +334,7 @@ def create_wrapper_by_url(
357
334
  config_dict["time_out"] = time_out
358
335
  config_dict["connection_time_out"] = connection_time_out
359
336
  config_dict["ssl_verify"] = ssl_verify
337
+ config_dict["trust_env"] = trust_env
360
338
  return create_wrapper_by_dict(config_dict, password)
361
339
 
362
340
 
@@ -367,7 +345,7 @@ def create_wrapper_by_dict(configuration: dict, password: str = "") -> SdkWrappe
367
345
  :param password: Password for the BaSyx server interface client, defaults to "".
368
346
  :return: An instance of SdkWrapper initialized with the provided parameters.
369
347
  """
370
- logger.info(f"Create AAS server wrapper from configuration '{configuration}'")
348
+ logger.info("Create AAS server wrapper from dictionary.")
371
349
  config_string = json.dumps(configuration, indent=4)
372
350
  return SdkWrapper(config_string, password)
373
351
 
@@ -379,7 +357,7 @@ def create_wrapper_by_config(config_file: Path, password: str = "") -> SdkWrappe
379
357
  :param password: password for the BaSyx server interface client, defaults to ""_
380
358
  :return: An instance of SdkWrapper initialized with the provided parameters.
381
359
  """
382
- logger.info(f"Create AAS wrapper client from configuration file '{config_file}'")
360
+ logger.info(f"Create AAS wrapper client from configuration file '{config_file}'.")
383
361
  if not config_file.exists():
384
362
  config_string = "{}"
385
363
  logger.warning(f"Configuration file '{config_file}' not found. Using default config.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.5
3
+ Version: 0.3.8
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
@@ -13,6 +13,7 @@ aas_http_client/core/version_check.py
13
13
  aas_http_client/demo/demo_process.py
14
14
  aas_http_client/utilities/__init__.py
15
15
  aas_http_client/utilities/model_builder.py
16
+ aas_http_client/utilities/sdk_tools.py
16
17
  aas_http_client/wrapper/sdk_wrapper.py
17
18
  tests/test_client.py
18
19
  tests/test_wrapper.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aas-http-client"
7
- version = "0.3.5"
7
+ version = "0.3.8"
8
8
  description = "Generic python HTTP client for communication with various types of AAS servers"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -3,6 +3,7 @@ from pathlib import Path
3
3
  from aas_http_client.client import create_client_by_config, AasHttpClient, create_client_by_dict, create_client_by_url
4
4
  from basyx.aas import model
5
5
  import aas_http_client.utilities.model_builder as model_builder
6
+ import aas_http_client.utilities.sdk_tools as sdk_tools
6
7
  import json
7
8
  import basyx.aas.adapter.json
8
9
  from urllib.parse import urlparse
@@ -41,22 +42,22 @@ def client(request) -> AasHttpClient:
41
42
  @pytest.fixture(scope="module")
42
43
  def shared_sme_string() -> model.Property:
43
44
  # create a Submodel
44
- return model_builder.create_base_submodel_element_Property("sme_property_string", model.datatypes.String, "Sample String Value")
45
+ return model_builder.create_base_submodel_element_property("sme_property_string", model.datatypes.String, "Sample String Value")
45
46
 
46
47
  @pytest.fixture(scope="module")
47
48
  def shared_sme_bool() -> model.Property:
48
49
  # create a Submodel
49
- return model_builder.create_base_submodel_element_Property("sme_property_bool", model.datatypes.Boolean, True)
50
+ return model_builder.create_base_submodel_element_property("sme_property_bool", model.datatypes.Boolean, True)
50
51
 
51
52
  @pytest.fixture(scope="module")
52
53
  def shared_sme_int() -> model.Property:
53
54
  # create a Submodel
54
- return model_builder.create_base_submodel_element_Property("sme_property_int", model.datatypes.Integer, 262)
55
+ return model_builder.create_base_submodel_element_property("sme_property_int", model.datatypes.Integer, 262)
55
56
 
56
57
  @pytest.fixture(scope="module")
57
58
  def shared_sme_float() -> model.Property:
58
59
  # create a Submodel
59
- return model_builder.create_base_submodel_element_Property("sme_property_float", model.datatypes.Float, 262.3)
60
+ return model_builder.create_base_submodel_element_property("sme_property_float", model.datatypes.Float, 262.3)
60
61
 
61
62
  @pytest.fixture(scope="module")
62
63
  def shared_sm() -> model.Submodel:
@@ -69,7 +70,7 @@ def shared_aas(shared_sm: model.Submodel) -> model.AssetAdministrationShell:
69
70
  aas = model_builder.create_base_ass(id_short="aas_http_client_unit_tests", namespace="")
70
71
 
71
72
  # add Submodel to AAS
72
- model_builder.add_submodel_to_aas(aas, shared_sm)
73
+ sdk_tools.add_submodel_to_aas(aas, shared_sm)
73
74
 
74
75
  return aas
75
76
 
@@ -3,6 +3,7 @@ from pathlib import Path
3
3
  from aas_http_client.wrapper.sdk_wrapper import create_wrapper_by_config, SdkWrapper, create_wrapper_by_dict, create_wrapper_by_url
4
4
  from basyx.aas import model
5
5
  import aas_http_client.utilities.model_builder as model_builder
6
+ import aas_http_client.utilities.sdk_tools as sdk_tools
6
7
  from urllib.parse import urlparse
7
8
  import json
8
9
 
@@ -41,22 +42,22 @@ def wrapper(request) -> SdkWrapper:
41
42
  @pytest.fixture(scope="module")
42
43
  def shared_sme_string() -> model.Property:
43
44
  # create a Submodel
44
- return model_builder.create_base_submodel_element_Property("sme_property_string", model.datatypes.String, "Sample String Value")
45
+ return model_builder.create_base_submodel_element_property("sme_property_string", model.datatypes.String, "Sample String Value")
45
46
 
46
47
  @pytest.fixture(scope="module")
47
48
  def shared_sme_bool() -> model.Property:
48
49
  # create a Submodel
49
- return model_builder.create_base_submodel_element_Property("sme_property_bool", model.datatypes.Boolean, True)
50
+ return model_builder.create_base_submodel_element_property("sme_property_bool", model.datatypes.Boolean, True)
50
51
 
51
52
  @pytest.fixture(scope="module")
52
53
  def shared_sme_int() -> model.Property:
53
54
  # create a Submodel
54
- return model_builder.create_base_submodel_element_Property("sme_property_int", model.datatypes.Integer, 262)
55
+ return model_builder.create_base_submodel_element_property("sme_property_int", model.datatypes.Integer, 262)
55
56
 
56
57
  @pytest.fixture(scope="module")
57
58
  def shared_sme_float() -> model.Property:
58
59
  # create a Submodel
59
- return model_builder.create_base_submodel_element_Property("sme_property_float", model.datatypes.Float, 262.3)
60
+ return model_builder.create_base_submodel_element_property("sme_property_float", model.datatypes.Float, 262.3)
60
61
 
61
62
  @pytest.fixture(scope="module")
62
63
  def shared_sm() -> model.Submodel:
@@ -71,7 +72,7 @@ def shared_aas(shared_sm: model.Submodel) -> model.AssetAdministrationShell:
71
72
  aas = model_builder.create_base_ass(id_short="aas_http_client_unit_tests", namespace="")
72
73
 
73
74
  # add Submodel to AAS
74
- model_builder.add_submodel_to_aas(aas, shared_sm)
75
+ sdk_tools.add_submodel_to_aas(aas, shared_sm)
75
76
 
76
77
  return aas
77
78
 
File without changes