openepd 7.1.0__py3-none-any.whl → 7.2.0__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.
Files changed (77) hide show
  1. openepd/__version__.py +1 -1
  2. openepd/api/average_dataset/generic_estimate_sync_api.py +2 -1
  3. openepd/api/average_dataset/industry_epd_sync_api.py +2 -1
  4. openepd/api/base_sync_client.py +10 -8
  5. openepd/api/common.py +17 -11
  6. openepd/api/dto/common.py +1 -1
  7. openepd/api/epd/sync_api.py +2 -1
  8. openepd/api/org/__init__.py +15 -0
  9. openepd/api/org/sync_api.py +79 -0
  10. openepd/api/pcr/sync_api.py +35 -0
  11. openepd/api/plant/__init__.py +15 -0
  12. openepd/api/plant/sync_api.py +79 -0
  13. openepd/api/standard/__init__.py +15 -0
  14. openepd/api/standard/sync_api.py +79 -0
  15. openepd/api/sync_client.py +27 -0
  16. openepd/bundle/base.py +5 -4
  17. openepd/bundle/reader.py +13 -7
  18. openepd/bundle/writer.py +11 -6
  19. openepd/m49/__init__.py +2 -0
  20. openepd/m49/const.py +1 -1
  21. openepd/m49/utils.py +16 -10
  22. openepd/model/base.py +20 -15
  23. openepd/model/common.py +10 -5
  24. openepd/model/declaration.py +2 -2
  25. openepd/model/epd.py +2 -1
  26. openepd/model/factory.py +5 -3
  27. openepd/model/generic_estimate.py +4 -0
  28. openepd/model/lcia.py +10 -10
  29. openepd/model/org.py +14 -7
  30. openepd/model/pcr.py +2 -2
  31. openepd/model/specs/__init__.py +37 -0
  32. openepd/model/specs/asphalt.py +3 -3
  33. openepd/model/specs/base.py +2 -1
  34. openepd/model/specs/enums.py +9 -1
  35. openepd/model/specs/range/__init__.py +5 -3
  36. openepd/model/specs/range/accessories.py +1 -1
  37. openepd/model/specs/range/aluminium.py +1 -1
  38. openepd/model/specs/range/cladding.py +10 -10
  39. openepd/model/specs/range/cmu.py +0 -2
  40. openepd/model/specs/range/concrete.py +25 -2
  41. openepd/model/specs/range/conveying_equipment.py +2 -2
  42. openepd/model/specs/range/electrical.py +18 -18
  43. openepd/model/specs/range/electrical_transmission_and_distribution_equipment.py +1 -1
  44. openepd/model/specs/range/exterior_improvements.py +47 -0
  45. openepd/model/specs/range/finishes.py +19 -40
  46. openepd/model/specs/range/fire_and_smoke_protection.py +3 -3
  47. openepd/model/specs/range/furnishings.py +7 -7
  48. openepd/model/specs/range/manufacturing_inputs.py +17 -5
  49. openepd/model/specs/range/masonry.py +1 -1
  50. openepd/model/specs/range/mechanical.py +6 -6
  51. openepd/model/specs/range/mixins/__init__.py +15 -0
  52. openepd/model/specs/range/mixins/access_flooring_mixin.py +43 -0
  53. openepd/model/specs/range/network_infrastructure.py +3 -3
  54. openepd/model/specs/range/openings.py +17 -17
  55. openepd/model/specs/range/other_materials.py +4 -4
  56. openepd/model/specs/range/plumbing.py +5 -5
  57. openepd/model/specs/range/precast_concrete.py +2 -2
  58. openepd/model/specs/range/steel.py +18 -9
  59. openepd/model/specs/range/thermal_moisture_protection.py +12 -12
  60. openepd/model/specs/range/wood.py +4 -6
  61. openepd/model/specs/singular/__init__.py +119 -2
  62. openepd/model/specs/singular/aluminium.py +2 -1
  63. openepd/model/specs/singular/concrete.py +25 -1
  64. openepd/model/specs/singular/deprecated/__init__.py +1 -1
  65. openepd/model/specs/singular/exterior_improvements.py +47 -0
  66. openepd/model/specs/singular/finishes.py +3 -59
  67. openepd/model/specs/singular/manufacturing_inputs.py +13 -1
  68. openepd/model/specs/singular/mixins/access_flooring_mixin.py +55 -0
  69. openepd/model/specs/singular/steel.py +10 -2
  70. openepd/model/validation/common.py +10 -6
  71. openepd/model/validation/enum.py +4 -2
  72. openepd/model/validation/quantity.py +13 -6
  73. openepd/model/versioning.py +8 -6
  74. {openepd-7.1.0.dist-info → openepd-7.2.0.dist-info}/METADATA +3 -4
  75. {openepd-7.1.0.dist-info → openepd-7.2.0.dist-info}/RECORD +77 -66
  76. {openepd-7.1.0.dist-info → openepd-7.2.0.dist-info}/WHEEL +1 -1
  77. {openepd-7.1.0.dist-info → openepd-7.2.0.dist-info}/LICENSE +0 -0
openepd/__version__.py CHANGED
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- VERSION = "7.1.0"
16
+ VERSION = "7.2.0"
@@ -135,7 +135,8 @@ class GenericEstimateApi(BaseApiMethodGroup):
135
135
  """
136
136
  ge_id = ge.id
137
137
  if not ge_id:
138
- raise ValueError("The ID must be set to edit a GenericEstimate.")
138
+ msg = "The ID must be set to edit a GenericEstimate."
139
+ raise ValueError(msg)
139
140
 
140
141
  response = self._client.do_request(
141
142
  "put",
@@ -90,7 +90,8 @@ class IndustryEpdApi(BaseApiMethodGroup):
90
90
  """
91
91
  iepd_id = iepd.id
92
92
  if not iepd_id:
93
- raise ValueError("The ID must be set to edit a IndustryEpd.")
93
+ msg = "The ID must be set to edit a IndustryEpd."
94
+ raise ValueError(msg)
94
95
 
95
96
  response = self._client.do_request(
96
97
  "put",
@@ -14,14 +14,15 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  __all__ = (
17
- "HttpStreamReader",
18
- "SyncHttpClient",
17
+ "USER_AGENT_DEFAULT",
18
+ "BaseApiMethodGroup",
19
19
  "DoRequest",
20
+ "HttpStreamReader",
20
21
  "RetryHandler",
21
- "BaseApiMethodGroup",
22
- "USER_AGENT_DEFAULT",
22
+ "SyncHttpClient",
23
23
  )
24
24
 
25
+ from collections.abc import Callable
25
26
  import datetime
26
27
  from functools import partial, wraps
27
28
  from io import IOBase
@@ -29,7 +30,7 @@ import logging
29
30
  import random
30
31
  import shutil
31
32
  import time
32
- from typing import IO, Any, BinaryIO, Callable, Final, NamedTuple
33
+ from typing import IO, Any, BinaryIO, Final, NamedTuple
33
34
 
34
35
  import requests
35
36
  from requests import PreparedRequest, Response, Session, Timeout
@@ -180,7 +181,7 @@ class SyncHttpClient:
180
181
  self._throttler = Throttler(rate_per_sec=requests_per_sec)
181
182
  self._throttle_retry_timeout: float = (
182
183
  float(throttle_retry_timeout)
183
- if isinstance(throttle_retry_timeout, (float, int))
184
+ if isinstance(throttle_retry_timeout, float | int)
184
185
  else throttle_retry_timeout.total_seconds()
185
186
  )
186
187
  self.user_agent = user_agent
@@ -412,7 +413,8 @@ class SyncHttpClient:
412
413
 
413
414
  response.raise_for_status()
414
415
  # This can't be handled by static checker because of the dynamic nature of the raise_for_status method
415
- raise RuntimeError("This line should never be reached")
416
+ msg = "This line should never be reached"
417
+ raise RuntimeError(msg)
416
418
 
417
419
  def _get_url_for_request(self, path_or_url: str) -> str:
418
420
  """
@@ -471,7 +473,7 @@ class SyncHttpClient:
471
473
  exception = e
472
474
 
473
475
  if exception or response.status_code == requests_codes.service_unavailable:
474
- secs = random.randint(60, 60 * 5)
476
+ secs = random.randint(60, 60 * 5) # noqa: S311
475
477
  logger.warning(
476
478
  "%s %s is unavailable. Attempts left: %s. Waiting %s seconds...",
477
479
  method,
openepd/api/common.py CHANGED
@@ -13,12 +13,12 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- from collections.abc import Iterable
16
+ from collections.abc import Callable, Iterable, Iterator
17
17
  from contextlib import contextmanager
18
18
  from datetime import datetime, timedelta
19
19
  import threading
20
20
  from time import sleep
21
- from typing import Callable, Generic, Iterator, cast
21
+ from typing import Generic, cast
22
22
 
23
23
  from requests import Response
24
24
 
@@ -126,20 +126,26 @@ class StreamingListResponse(Iterable[TOpenEpdObject], Generic[TOpenEpdObject]):
126
126
  :return: list of items on the page
127
127
  """
128
128
  if page_num <= 0:
129
- raise ValueError("Page number must be positive")
129
+ msg = "Page number must be positive"
130
+ raise ValueError(msg)
130
131
  if self.__current_page != page_num or force_reload:
131
132
  self.__recent_response = self.__fetch_handler(page_num, self.__page_size)
132
133
  self.__current_page = page_num
133
134
  if self.__recent_response is None:
134
- raise RuntimeError("Response is empty, this should not happen, check if fetch_handler is compatible")
135
+ msg = "Response is empty, this should not happen, check if fetch_handler is compatible"
136
+ raise RuntimeError(msg)
135
137
  if self.__recent_response.payload is None:
136
- raise ValueError("Response does not contain payload")
138
+ msg = "Response does not contain payload"
139
+ raise ValueError(msg)
137
140
  if not isinstance(self.__recent_response.payload, list):
138
- raise ValueError("Response does not contain a list")
141
+ msg = "Response does not contain a list"
142
+ raise ValueError(msg)
139
143
  if self.__recent_response.meta is None:
140
- raise ValueError("Response does not contain meta")
144
+ msg = "Response does not contain meta"
145
+ raise ValueError(msg)
141
146
  if not isinstance(self.__recent_response.meta, PagingMetaMixin):
142
- raise ValueError("Response does not contain paging meta")
147
+ msg = "Response does not contain paging meta"
148
+ raise ValueError(msg)
143
149
  return self.__recent_response.payload
144
150
 
145
151
  def get_paging_meta(self) -> PagingMeta:
@@ -152,7 +158,8 @@ class StreamingListResponse(Iterable[TOpenEpdObject], Generic[TOpenEpdObject]):
152
158
  """
153
159
  paging_meta = cast(PagingMetaMixin, self.get_meta()).paging
154
160
  if paging_meta is None:
155
- raise ValueError("Response does not contain paging meta")
161
+ msg = "Response does not contain paging meta"
162
+ raise ValueError(msg)
156
163
  return paging_meta
157
164
 
158
165
  def get_meta(self) -> MetaCollectionDto:
@@ -206,8 +213,7 @@ class StreamingListResponse(Iterable[TOpenEpdObject], Generic[TOpenEpdObject]):
206
213
  self.goto_page(start_from_page)
207
214
  while True:
208
215
  items = self.goto_page(self.current_page)
209
- for x in items:
210
- yield x
216
+ yield from items
211
217
  if not self.has_next_page():
212
218
  return # no more pages
213
219
  else:
openepd/api/dto/common.py CHANGED
@@ -63,7 +63,7 @@ TMetaExtension = TypeVar("TMetaExtension", bound=MetaExtensionBase)
63
63
 
64
64
  class MetaCollectionDto(BaseOpenEpdApiModel, Generic[TMetaExtension]):
65
65
  """
66
- This class is intended to be used as a container for different meta objects.
66
+ Use this class as a container for different meta objects.
67
67
 
68
68
  From a specific controller, you should return a specific subclass of MetaCollectionDto and appropriate mixins. This
69
69
  would allow to retain type information to generate schema for meta section of response.
@@ -173,7 +173,8 @@ class EpdApi(BaseApiMethodGroup):
173
173
  """
174
174
  epd_id = epd.id
175
175
  if not epd_id:
176
- raise ValueError("The EPD ID must be set to edit an EPD.")
176
+ msg = "The EPD ID must be set to edit an EPD."
177
+ raise ValueError(msg)
177
178
  response = self._client.do_request(
178
179
  "put",
179
180
  f"/epds/{encode_path_param(epd_id)}",
@@ -0,0 +1,15 @@
1
+ #
2
+ # Copyright 2025 by C Change Labs Inc. www.c-change-labs.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
@@ -0,0 +1,79 @@
1
+ #
2
+ # Copyright 2025 by C Change Labs Inc. www.c-change-labs.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from typing import Literal, overload
17
+
18
+ from requests import Response
19
+
20
+ from openepd.api.base_sync_client import BaseApiMethodGroup
21
+ from openepd.api.utils import encode_path_param
22
+ from openepd.model.org import Org, OrgRef
23
+
24
+
25
+ class OrgApi(BaseApiMethodGroup):
26
+ """API methods for Orgs."""
27
+
28
+ @overload
29
+ def create(self, to_create: Org, with_response: Literal[True]) -> tuple[OrgRef, Response]: ...
30
+
31
+ @overload
32
+ def create(self, to_create: Org, with_response: Literal[False] = False) -> OrgRef: ...
33
+
34
+ def create(self, to_create: Org, with_response: bool = False) -> OrgRef | tuple[OrgRef, Response]:
35
+ """
36
+ Create a new organization.
37
+
38
+ :param to_create: Organization to create
39
+ :param with_response: if True, return a tuple of (OrgRef, Response), otherwise return only OrgRef
40
+ :return: Organization reference or Organization reference with HTTP Response object depending on parameter
41
+ :raise ValidationError: if given object Org is invalid
42
+ """
43
+ response = self._client.do_request("post", "/orgs", json=to_create.to_serializable())
44
+ content = response.json()
45
+ ref = OrgRef.model_validate(content)
46
+ if with_response:
47
+ return ref, response
48
+ return ref
49
+
50
+ @overload
51
+ def edit(self, to_edit: Org, with_response: Literal[True]) -> tuple[OrgRef, Response]: ...
52
+
53
+ @overload
54
+ def edit(self, to_edit: Org, with_response: Literal[False] = False) -> OrgRef: ...
55
+
56
+ def edit(self, to_edit: Org, with_response: bool = False) -> OrgRef | tuple[OrgRef, Response]:
57
+ """
58
+ Edit an organization.
59
+
60
+ :param to_edit: Organization to edit
61
+ :param with_response: if True, return a tuple of (OrgRef, Response), otherwise return only Org
62
+ :return: Organization reference or Organization reference with HTTP Response object depending on parameter
63
+ :raise ValueError: if the organization web_domain is not set
64
+ """
65
+ entity_id = to_edit.web_domain
66
+ if not entity_id:
67
+ msg = "The organization web_domain must be set to edit an organization."
68
+ raise ValueError(msg)
69
+ response = self._client.do_request(
70
+ "put",
71
+ f"/orgs/{encode_path_param(entity_id)}",
72
+ json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
73
+ )
74
+ response.raise_for_status()
75
+ content = response.json()
76
+ ref = OrgRef.model_validate(content)
77
+ if with_response:
78
+ return ref, response
79
+ return ref
@@ -13,7 +13,12 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
+ from typing import Literal, overload
17
+
18
+ from requests import Response
19
+
16
20
  from openepd.api.base_sync_client import BaseApiMethodGroup
21
+ from openepd.api.utils import encode_path_param
17
22
  from openepd.model.pcr import Pcr, PcrRef
18
23
 
19
24
 
@@ -42,3 +47,33 @@ class PcrApi(BaseApiMethodGroup):
42
47
  """
43
48
  pcr_ref_obj = self._client.do_request("post", "/pcrs", json=pcr.to_serializable()).json()
44
49
  return PcrRef.model_validate(pcr_ref_obj)
50
+
51
+ @overload
52
+ def edit(self, to_edit: Pcr, with_response: Literal[True]) -> tuple[PcrRef, Response]: ...
53
+
54
+ @overload
55
+ def edit(self, to_edit: Pcr, with_response: Literal[False] = False) -> PcrRef: ...
56
+
57
+ def edit(self, to_edit: Pcr, with_response: bool = False) -> PcrRef | tuple[PcrRef, Response]:
58
+ """
59
+ Edit a pcr.
60
+
61
+ :param to_edit: Pcr to edit
62
+ :param with_response: if True, return a tuple of (PcrRef, Response), otherwise return only PcrRef
63
+ :return: Pcr reference or Pcr reference with HTTP Response object depending on parameter
64
+ :raise ValueError: if the pcr ID is not set
65
+ """
66
+ entity_id = to_edit.id
67
+ if not entity_id:
68
+ msg = "The pcr ID must be set to edit a pcr."
69
+ raise ValueError(msg)
70
+ response = self._client.do_request(
71
+ "put",
72
+ f"/pcrs/{encode_path_param(entity_id)}",
73
+ json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
74
+ )
75
+ content = response.json()
76
+ ref = PcrRef.model_validate(content)
77
+ if with_response:
78
+ return ref, response
79
+ return ref
@@ -0,0 +1,15 @@
1
+ #
2
+ # Copyright 2025 by C Change Labs Inc. www.c-change-labs.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
@@ -0,0 +1,79 @@
1
+ #
2
+ # Copyright 2025 by C Change Labs Inc. www.c-change-labs.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from typing import Literal, overload
17
+
18
+ from requests import Response
19
+
20
+ from openepd.api.base_sync_client import BaseApiMethodGroup
21
+ from openepd.api.utils import encode_path_param
22
+ from openepd.model.org import Plant, PlantRef
23
+
24
+
25
+ class PlantApi(BaseApiMethodGroup):
26
+ """API methods for Plants."""
27
+
28
+ @overload
29
+ def create(self, to_create: Plant, with_response: Literal[True]) -> tuple[PlantRef, Response]: ...
30
+
31
+ @overload
32
+ def create(self, to_create: Plant, with_response: Literal[False] = False) -> PlantRef: ...
33
+
34
+ def create(self, to_create: Plant, with_response: bool = False) -> PlantRef | tuple[PlantRef, Response]:
35
+ """
36
+ Create a new plant.
37
+
38
+ :param to_create: Plant to create
39
+ :param with_response: if True, return a tuple of (PlantRef, Response), otherwise return only PlantRef
40
+ :return: Plant reference or Plant reference with HTTP Response object depending on parameter
41
+ :raise ValidationError: if given object Plant is invalid
42
+ """
43
+ response = self._client.do_request("post", "/plants", json=to_create.to_serializable())
44
+ content = response.json()
45
+ ref = PlantRef.model_validate(content)
46
+ if with_response:
47
+ return ref, response
48
+ return ref
49
+
50
+ @overload
51
+ def edit(self, to_edit: Plant, with_response: Literal[True]) -> tuple[PlantRef, Response]: ...
52
+
53
+ @overload
54
+ def edit(self, to_edit: Plant, with_response: Literal[False] = False) -> PlantRef: ...
55
+
56
+ def edit(self, to_edit: Plant, with_response: bool = False) -> PlantRef | tuple[PlantRef, Response]:
57
+ """
58
+ Edit a plant.
59
+
60
+ :param to_edit: Plant to edit
61
+ :param with_response: if True, return a tuple of (PlantRef, Response), otherwise return only PlantRef
62
+ :return: Plant reference or Plant reference with HTTP Response object depending on parameter
63
+ :raise ValueError: if the plant ID is not set
64
+ """
65
+ entity_id = to_edit.id
66
+ if not entity_id:
67
+ msg = "The plant ID must be set to edit a plant."
68
+ raise ValueError(msg)
69
+ response = self._client.do_request(
70
+ "put",
71
+ f"/plants/{encode_path_param(entity_id)}",
72
+ json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
73
+ )
74
+ response.raise_for_status()
75
+ content = response.json()
76
+ ref = PlantRef.model_validate(content)
77
+ if with_response:
78
+ return ref, response
79
+ return ref
@@ -0,0 +1,15 @@
1
+ #
2
+ # Copyright 2025 by C Change Labs Inc. www.c-change-labs.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
@@ -0,0 +1,79 @@
1
+ #
2
+ # Copyright 2025 by C Change Labs Inc. www.c-change-labs.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from typing import Literal, overload
17
+
18
+ from requests import Response
19
+
20
+ from openepd.api.base_sync_client import BaseApiMethodGroup
21
+ from openepd.api.utils import encode_path_param
22
+ from openepd.model.standard import Standard, StandardRef
23
+
24
+
25
+ class StandardApi(BaseApiMethodGroup):
26
+ """API methods for Standards."""
27
+
28
+ @overload
29
+ def create(self, to_create: Standard, with_response: Literal[True]) -> tuple[StandardRef, Response]: ...
30
+
31
+ @overload
32
+ def create(self, to_create: Standard, with_response: Literal[False] = False) -> StandardRef: ...
33
+
34
+ def create(self, to_create: Standard, with_response: bool = False) -> StandardRef | tuple[StandardRef, Response]:
35
+ """
36
+ Create a new standard.
37
+
38
+ :param to_create: Standard to create
39
+ :param with_response: if True, return a tuple of (StandardRef, Response), otherwise return only StandardRef
40
+ :return: Standard reference or Standard reference with HTTP Response object depending on parameter
41
+ :raise ValidationError: if given object Standard is invalid
42
+ """
43
+ response = self._client.do_request("post", "/standards", json=to_create.to_serializable())
44
+ content = response.json()
45
+ ref = StandardRef.model_validate(content)
46
+ if with_response:
47
+ return ref, response
48
+ return ref
49
+
50
+ @overload
51
+ def edit(self, to_edit: Standard, with_response: Literal[True]) -> tuple[StandardRef, Response]: ...
52
+
53
+ @overload
54
+ def edit(self, to_edit: Standard, with_response: Literal[False] = False) -> StandardRef: ...
55
+
56
+ def edit(self, to_edit: Standard, with_response: bool = False) -> StandardRef | tuple[StandardRef, Response]:
57
+ """
58
+ Edit a standard.
59
+
60
+ :param to_edit: Standard to edit
61
+ :param with_response: if True, return a tuple of (StandardRef, Response), otherwise return only StandardRef
62
+ :return: Standard reference or Standard reference with HTTP Response object depending on parameter
63
+ :raise ValueError: if the standard short_name is not set
64
+ """
65
+ entity_id = to_edit.short_name
66
+ if not entity_id:
67
+ msg = "The standard short_name must be set to edit a standard."
68
+ raise ValueError(msg)
69
+ response = self._client.do_request(
70
+ "put",
71
+ f"/standards/{encode_path_param(entity_id)}",
72
+ json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
73
+ )
74
+ response.raise_for_status()
75
+ content = response.json()
76
+ ref = StandardRef.model_validate(content)
77
+ if with_response:
78
+ return ref, response
79
+ return ref
@@ -22,7 +22,10 @@ from openepd.api.average_dataset.industry_epd_sync_api import IndustryEpdApi
22
22
  from openepd.api.base_sync_client import SyncHttpClient, TokenAuth
23
23
  from openepd.api.category.sync_api import CategoryApi
24
24
  from openepd.api.epd.sync_api import EpdApi
25
+ from openepd.api.org.sync_api import OrgApi
25
26
  from openepd.api.pcr.sync_api import PcrApi
27
+ from openepd.api.plant.sync_api import PlantApi
28
+ from openepd.api.standard.sync_api import StandardApi
26
29
 
27
30
 
28
31
  class OpenEpdApiClientSync:
@@ -41,6 +44,9 @@ class OpenEpdApiClientSync:
41
44
  self._http_client = SyncHttpClient(base_url, auth=auth, **kwargs)
42
45
  self.__epd_api: EpdApi | None = None
43
46
  self.__pcr_api: PcrApi | None = None
47
+ self.__org_api: OrgApi | None = None
48
+ self.__plant_api: PlantApi | None = None
49
+ self.__standard_api: StandardApi | None = None
44
50
  self.__category_api: CategoryApi | None = None
45
51
  self.__generic_estimate_api: GenericEstimateApi | None = None
46
52
  self.__industry_epd_api: IndustryEpdApi | None = None
@@ -59,6 +65,27 @@ class OpenEpdApiClientSync:
59
65
  self.__pcr_api = PcrApi(self._http_client)
60
66
  return self.__pcr_api
61
67
 
68
+ @property
69
+ def orgs(self) -> OrgApi:
70
+ """Get the Org API."""
71
+ if self.__org_api is None:
72
+ self.__org_api = OrgApi(self._http_client)
73
+ return self.__org_api
74
+
75
+ @property
76
+ def plants(self) -> PlantApi:
77
+ """Get the Plant API."""
78
+ if self.__plant_api is None:
79
+ self.__plant_api = PlantApi(self._http_client)
80
+ return self.__plant_api
81
+
82
+ @property
83
+ def standards(self) -> StandardApi:
84
+ """Get the Standard API."""
85
+ if self.__standard_api is None:
86
+ self.__standard_api = StandardApi(self._http_client)
87
+ return self.__standard_api
88
+
62
89
  @property
63
90
  def categories(self) -> CategoryApi:
64
91
  """Get the Category API."""
openepd/bundle/base.py CHANGED
@@ -14,8 +14,9 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  import abc
17
+ from collections.abc import Callable, Iterator, Sequence
17
18
  import csv
18
- from typing import IO, Callable, Iterator, Self, Sequence, Type
19
+ from typing import IO, Self
19
20
 
20
21
  from openepd.bundle.model import AssetInfo, AssetType, BundleManifest, RelType
21
22
  from openepd.model.base import TOpenEpdObject
@@ -70,7 +71,7 @@ class BaseBundleReader(BundleMixin, metaclass=abc.ABCMeta):
70
71
  def __enter__(self) -> Self:
71
72
  return self
72
73
 
73
- def __exit__(self, type, value, traceback):
74
+ def __exit__(self, type, value, traceback): # noqa: A002
74
75
  self.close()
75
76
 
76
77
  @abc.abstractmethod
@@ -133,7 +134,7 @@ class BaseBundleReader(BundleMixin, metaclass=abc.ABCMeta):
133
134
  pass
134
135
 
135
136
  @abc.abstractmethod
136
- def read_object_asset(self, obj_class: Type[TOpenEpdObject], asset_ref: AssetRef) -> TOpenEpdObject:
137
+ def read_object_asset(self, obj_class: type[TOpenEpdObject], asset_ref: AssetRef) -> TOpenEpdObject:
137
138
  """Read an object asset by given reference."""
138
139
  pass
139
140
 
@@ -171,7 +172,7 @@ class BaseBundleWriter(BundleMixin, metaclass=abc.ABCMeta):
171
172
  def __enter__(self) -> Self:
172
173
  return self
173
174
 
174
- def __exit__(self, type, value, traceback):
175
+ def __exit__(self, type, value, traceback): # noqa: A002
175
176
  self.close()
176
177
 
177
178
  @abc.abstractmethod
openepd/bundle/reader.py CHANGED
@@ -13,10 +13,11 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
+ from collections.abc import Callable, Iterator, Sequence
16
17
  import csv
17
18
  import io
18
19
  from os import PathLike
19
- from typing import IO, Callable, Iterator, Sequence, Type, cast
20
+ from typing import IO, cast
20
21
  import zipfile
21
22
 
22
23
  from openepd.bundle.base import AssetFilter, AssetRef, BaseBundleReader
@@ -95,7 +96,8 @@ class DefaultBundleReader(BaseBundleReader):
95
96
  with self._bundle_archive.open("toc", "r") as toc_stream:
96
97
  toc_reader = csv.DictReader(io.TextIOWrapper(toc_stream, encoding="utf-8"), dialect="toc")
97
98
  if not toc_reader.fieldnames or len(toc_reader.fieldnames) < len(self._TOC_FIELDS):
98
- raise ValueError("The bundle file is not valid. TOC reading error: wrong number of fields")
99
+ msg = "The bundle file is not valid. TOC reading error: wrong number of fields"
100
+ raise ValueError(msg)
99
101
 
100
102
  def root_assets_iter(
101
103
  self,
@@ -148,17 +150,21 @@ class DefaultBundleReader(BaseBundleReader):
148
150
  """Read the blob asset."""
149
151
  asset = self.get_asset_by_ref(asset_ref)
150
152
  if asset is None:
151
- raise ValueError("Asset not found")
153
+ msg = "Asset not found"
154
+ raise ValueError(msg)
152
155
  return self._bundle_archive.open(asset.ref, "r")
153
156
 
154
- def read_object_asset(self, obj_class: Type[TOpenEpdObject], asset_ref: AssetRef) -> TOpenEpdObject:
157
+ def read_object_asset(self, obj_class: type[TOpenEpdObject], asset_ref: AssetRef) -> TOpenEpdObject:
155
158
  """Read the object asset."""
156
159
  asset = self.get_asset_by_ref(asset_ref)
157
160
  if asset is None:
158
- raise ValueError("Asset not found")
161
+ msg = "Asset not found"
162
+ raise ValueError(msg)
159
163
  if obj_class.get_asset_type() is None:
160
- raise ValueError(f"Target object {obj_class.__name__} is not supported asset")
164
+ msg = f"Target object {obj_class.__name__} is not supported asset"
165
+ raise ValueError(msg)
161
166
  if asset.type != obj_class.get_asset_type():
162
- raise ValueError(f"Asset type mismatch. Expected {obj_class.get_asset_type()}, got {asset.type}")
167
+ msg = f"Asset type mismatch. Expected {obj_class.get_asset_type()}, got {asset.type}"
168
+ raise ValueError(msg)
163
169
  with self._bundle_archive.open(asset.ref, "r") as asset_stream:
164
170
  return obj_class.model_validate_json(asset_stream.read())