stidapi 1.4.5__tar.gz → 1.5.1__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.
stidapi-1.5.1/PKG-INFO ADDED
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: stidapi
3
+ Version: 1.5.1
4
+ Summary: Python client for connecting to Equinor STIDapi
5
+ Author: Åsmund Våge Fannemel
6
+ Author-email: Åsmund Våge Fannemel <asmf@equinor.com>
7
+ License-Expression: LicenseRef-Proprietary
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Dist: eq-api-connector>=1.3.0,<2
15
+ Requires-Python: >=3.10, <4
16
+ Project-URL: repository, https://github.com/equinor/STIDapi-python
17
+ Description-Content-Type: text/markdown
18
+
19
+ # STIDapi-python
20
+ A simple wrapper package to interface Equinor [STIDapi](https://stidapi.equinor.com/) using python and get plant, system, tag and doc data.
21
+
22
+
23
+ ## Use
24
+
25
+ Try it out by running the [demo](examples/demo.py) or the sample code below.
26
+
27
+ ```
28
+ from stidapi import Plant, Tag, Doc
29
+
30
+
31
+ p = Plant("JSV")
32
+ t = p.search_tag("*20LIC*")
33
+ tag_no = t[0].no
34
+ t2 = Tag("JSV", tag_no)
35
+
36
+
37
+ d = t2.get_doc()
38
+ doc_no = d[0].no
39
+ d2 = p.get_doc(doc_no)
40
+ d3 = Doc(p.inst_code, doc_no)
41
+ ```
42
+
43
+ ## Installing
44
+
45
+ Install package from pypi using `pip install stidapi`
46
+
47
+ ## Client configuration
48
+
49
+ All resource reads share one lazily initialized `STIDApiClient`. To customize
50
+ it, configure and register it before any resource reads or concurrent workers:
51
+
52
+ ```python
53
+ from stidapi import STIDApiClient, get_api_client, set_api_client
54
+
55
+ client = STIDApiClient()
56
+ set_api_client(client)
57
+ assert get_api_client() is client
58
+ ```
59
+
60
+ The existing accessors in `stidapi.utils` remain available. Registering the same
61
+ instance again is allowed, but replacing the shared client raises `RuntimeError`.
62
+ The shared client and plant cache support one identity and gateway per process;
63
+ do not change either after resource reads. Separate identities or gateways require
64
+ separate processes. Provider initialization is thread-safe, but this does not
65
+ guarantee that concurrent requests using the connector are thread-safe.
66
+
67
+ ## Document-reference errors (1.5.1)
68
+
69
+ `Tag.get_doc_references()` and `Tag.get_doc()` return an empty list only when
70
+ the document-reference endpoint successfully returns an empty JSON array.
71
+ HTTP errors propagate as `requests.HTTPError`; unexpected response shapes
72
+ (including null, an error object, or non-dictionary array entries) raise
73
+ `ValueError` rather than being treated as missing documents. Other connector
74
+ exceptions also propagate. The shared JSON helpers retain their existing behavior
75
+ for other resource methods.
76
+
77
+ ## Developing / testing
78
+
79
+ Dependency manager uv is preferred for developers. Install with required packages for testing and coverage:
80
+ `uv sync`
81
+
82
+ Call `uv run pytest` to run tests.
83
+
84
+ Run the offline client lifecycle and document-reference tests with
85
+ `uv run pytest -m ci`.
86
+ The remaining legacy tests are not classified by that marker and include live
87
+ STID calls requiring authorized access; the full suite is not CI-safe.
88
+
89
+ To generate coverage report run `uv run pytest --cov=stidapi tests/ --cov-report=xml`
90
+
91
+ To compare coverage with master branch run
92
+ `uv run diff-cover coverage.xml --compare-branch master`
93
+
@@ -0,0 +1,75 @@
1
+ # STIDapi-python
2
+ A simple wrapper package to interface Equinor [STIDapi](https://stidapi.equinor.com/) using python and get plant, system, tag and doc data.
3
+
4
+
5
+ ## Use
6
+
7
+ Try it out by running the [demo](examples/demo.py) or the sample code below.
8
+
9
+ ```
10
+ from stidapi import Plant, Tag, Doc
11
+
12
+
13
+ p = Plant("JSV")
14
+ t = p.search_tag("*20LIC*")
15
+ tag_no = t[0].no
16
+ t2 = Tag("JSV", tag_no)
17
+
18
+
19
+ d = t2.get_doc()
20
+ doc_no = d[0].no
21
+ d2 = p.get_doc(doc_no)
22
+ d3 = Doc(p.inst_code, doc_no)
23
+ ```
24
+
25
+ ## Installing
26
+
27
+ Install package from pypi using `pip install stidapi`
28
+
29
+ ## Client configuration
30
+
31
+ All resource reads share one lazily initialized `STIDApiClient`. To customize
32
+ it, configure and register it before any resource reads or concurrent workers:
33
+
34
+ ```python
35
+ from stidapi import STIDApiClient, get_api_client, set_api_client
36
+
37
+ client = STIDApiClient()
38
+ set_api_client(client)
39
+ assert get_api_client() is client
40
+ ```
41
+
42
+ The existing accessors in `stidapi.utils` remain available. Registering the same
43
+ instance again is allowed, but replacing the shared client raises `RuntimeError`.
44
+ The shared client and plant cache support one identity and gateway per process;
45
+ do not change either after resource reads. Separate identities or gateways require
46
+ separate processes. Provider initialization is thread-safe, but this does not
47
+ guarantee that concurrent requests using the connector are thread-safe.
48
+
49
+ ## Document-reference errors (1.5.1)
50
+
51
+ `Tag.get_doc_references()` and `Tag.get_doc()` return an empty list only when
52
+ the document-reference endpoint successfully returns an empty JSON array.
53
+ HTTP errors propagate as `requests.HTTPError`; unexpected response shapes
54
+ (including null, an error object, or non-dictionary array entries) raise
55
+ `ValueError` rather than being treated as missing documents. Other connector
56
+ exceptions also propagate. The shared JSON helpers retain their existing behavior
57
+ for other resource methods.
58
+
59
+ ## Developing / testing
60
+
61
+ Dependency manager uv is preferred for developers. Install with required packages for testing and coverage:
62
+ `uv sync`
63
+
64
+ Call `uv run pytest` to run tests.
65
+
66
+ Run the offline client lifecycle and document-reference tests with
67
+ `uv run pytest -m ci`.
68
+ The remaining legacy tests are not classified by that marker and include live
69
+ STID calls requiring authorized access; the full suite is not CI-safe.
70
+
71
+ To generate coverage report run `uv run pytest --cov=stidapi tests/ --cov-report=xml`
72
+
73
+ To compare coverage with master branch run
74
+ `uv run diff-cover coverage.xml --compare-branch master`
75
+
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stidapi"
3
- version = "1.4.5"
3
+ version = "1.5.1"
4
4
  description = "Python client for connecting to Equinor STIDapi"
5
5
  requires-python = ">=3.10,<4"
6
6
  readme = "README.md"
@@ -13,7 +13,7 @@ classifiers = [
13
13
  "Programming Language :: Python :: 3.13",
14
14
  "Programming Language :: Python :: 3.14",
15
15
  ]
16
- dependencies = ["eq-api-connector>=1.2.0,<2"]
16
+ dependencies = ["eq-api-connector>=1.3.0,<2"]
17
17
 
18
18
  [[project.authors]]
19
19
  name = "Åsmund Våge Fannemel"
@@ -33,3 +33,6 @@ dev = [
33
33
  [build-system]
34
34
  requires = ["uv_build>=0.11.16,<0.14.0"]
35
35
  build-backend = "uv_build"
36
+
37
+ [tool.pytest.ini_options]
38
+ markers = ["ci: offline tests without credentials or network access"]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stidapi"
3
- version = "1.4.5"
3
+ version = "1.5.1"
4
4
  description = "Python client for connecting to Equinor STIDapi"
5
5
  authors = [{ name = "Åsmund Våge Fannemel", email = "asmf@equinor.com" }]
6
6
  requires-python = ">=3.10,<4"
@@ -14,7 +14,7 @@ classifiers = [
14
14
  "Programming Language :: Python :: 3.13",
15
15
  "Programming Language :: Python :: 3.14",
16
16
  ]
17
- dependencies = ["eq-api-connector>=1.2.0,<2"]
17
+ dependencies = ["eq-api-connector>=1.3.0,<2"]
18
18
 
19
19
  [project.urls]
20
20
  repository = "https://github.com/equinor/STIDapi-python"
@@ -30,3 +30,6 @@ dev = [
30
30
  [build-system]
31
31
  requires = ["uv_build>=0.11.16,<0.14.0"]
32
32
  build-backend = "uv_build"
33
+
34
+ [tool.pytest.ini_options]
35
+ markers = ["ci: offline tests without credentials or network access"]
@@ -0,0 +1,19 @@
1
+ import logging
2
+
3
+ from .doc import Doc
4
+ from .tag import Tag
5
+ from .plant import Plant
6
+ from .system import System
7
+ from .utils import STIDApiClient, get_api_client, set_api_client
8
+
9
+ __all__ = [
10
+ "Doc",
11
+ "Tag",
12
+ "Plant",
13
+ "System",
14
+ "STIDApiClient",
15
+ "get_api_client",
16
+ "set_api_client",
17
+ ]
18
+
19
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
@@ -93,7 +93,9 @@ class Plant:
93
93
  if len(cls._plant_list) == 0:
94
94
  parsed_json = u.get_json_list("/plants")
95
95
 
96
- cls._plant_list = [x for x in parsed_json if isinstance(x, dict) and "instCode" in x]
96
+ cls._plant_list = [
97
+ x for x in parsed_json if isinstance(x, dict) and "instCode" in x
98
+ ]
97
99
 
98
100
  return cls._plant_list
99
101
 
@@ -209,6 +209,10 @@ class Tag:
209
209
 
210
210
  Returns:
211
211
  List[Doc]: List of referred Documents
212
+
213
+ Raises:
214
+ requests.HTTPError: If the document-reference request fails.
215
+ ValueError: If document references are not a list of dictionaries.
212
216
  """
213
217
  return [Doc.from_data(x) for x in self.get_doc_references()]
214
218
 
@@ -217,12 +221,24 @@ class Tag:
217
221
 
218
222
  Returns:
219
223
  List[dict]: List of dicts describing document references.
224
+
225
+ Raises:
226
+ requests.HTTPError: If the request returns an HTTP error.
227
+ ValueError: If the response is not a list of dictionaries.
220
228
  """
221
229
  url = u.build_url(
222
230
  f"{self.inst_code}/tag/document-refs",
223
231
  {"tagNo": self.tag_no, "noContentAs200": True},
224
232
  )
225
- return [item for item in u.get_json_list(url) if isinstance(item, dict)]
233
+ references = u.get_json(url, raise_for_status=True)
234
+ if not isinstance(references, list) or any(
235
+ not isinstance(item, dict) for item in references
236
+ ):
237
+ raise ValueError(
238
+ f"Invalid document references for {self.inst_code}/{self.tag_no}: "
239
+ "expected a list of dictionaries"
240
+ )
241
+ return references
226
242
 
227
243
  def get_functional_location(self) -> str:
228
244
  """Get functional location of Tagged item or empty string if it does not have a functional location.
@@ -352,6 +368,7 @@ class Tag:
352
368
  value: str = "",
353
369
  inst_code: Optional[Union[str, List[str]]] = None,
354
370
  stop_first: bool = True,
371
+ max_workers: int = 4,
355
372
  ) -> List["Tag"]:
356
373
  """Get List of Tag objects by searching for additional fields
357
374
 
@@ -361,7 +378,8 @@ class Tag:
361
378
  inst_code: STID plant code, or list of codes, to limit search to.
362
379
  Defaults to empty which will search all.
363
380
  stop_first (boolean): Set to False to get matches from all provided inst_code,
364
- else will stop at first match. Defaults to False.
381
+ else will stop at the first matching installation. Defaults to True.
382
+ max_workers (int): Maximum concurrent installation searches. Defaults to 4.
365
383
 
366
384
  Returns:
367
385
  List[Tag): List of Tag objects
@@ -375,18 +393,34 @@ class Tag:
375
393
  if isinstance(inst_code, str):
376
394
  inst_code = [inst_code]
377
395
 
396
+ if max_workers < 1:
397
+ raise ValueError("max_workers must be at least 1")
398
+
399
+ inst_codes = list(inst_code)
378
400
  res = []
379
- for code in inst_code:
380
- try:
381
- res_code = Tag.search_additional_field(
382
- inst_code=code, field_name=field_name, value=value
401
+ for start in range(0, len(inst_codes), max_workers):
402
+ codes = inst_codes[start : start + max_workers]
403
+ urls = [
404
+ u.build_url(
405
+ f"{code}/tag-additional-field/{field_name}",
406
+ {"searchValue": value, "noContentAs200": True},
383
407
  )
408
+ for code in codes
409
+ ]
410
+ try:
411
+ responses = u.get_json_lists(urls, max_workers=max_workers)
384
412
  except ValueError:
385
413
  continue
386
- if len(res_code) > 0:
387
- res.extend(res_code)
388
-
389
- if stop_first:
390
- break
414
+ for code, response in zip(codes, responses):
415
+ res_code = [
416
+ Tag(inst_code=code, tag_no=item["tagNo"], data=item)
417
+ for item in response
418
+ if isinstance(item, dict) and "tagNo" in item
419
+ ]
420
+ if res_code:
421
+ res.extend(res_code)
422
+
423
+ if stop_first:
424
+ return res
391
425
 
392
426
  return res
@@ -2,13 +2,11 @@ import json
2
2
  import logging
3
3
  from typing import Any, Dict, List, Optional, Union
4
4
  from urllib.parse import urlencode, urljoin
5
- from eq_api_connector import APIConnector
5
+ from eq_api_connector import APIConnector, ClientProvider
6
6
  from types import SimpleNamespace
7
7
 
8
8
  logger = logging.getLogger(__name__)
9
9
 
10
- _client = None
11
-
12
10
  _scope_client = "1734406c-3449-4192-a50d-7c3a63d3f57d"
13
11
 
14
12
 
@@ -33,19 +31,26 @@ class STIDApiClient(APIConnector):
33
31
  # todo: set dev url
34
32
 
35
33
 
34
+ _provider = ClientProvider(STIDApiClient)
35
+
36
+
36
37
  def get_api_client() -> STIDApiClient:
37
- global _client
38
- if _client is None:
39
- client = STIDApiClient()
40
- set_api_client(client)
41
- return client
38
+ """Return the shared client, creating it lazily on first use."""
39
+ return _provider.get()
40
+
42
41
 
43
- return _client
42
+ def set_api_client(client: STIDApiClient) -> None:
43
+ """Register a configured client before resource reads or starting workers.
44
44
 
45
+ The same instance may be registered again. A different client cannot replace
46
+ the registered or lazily initialized client because resource data is cached.
47
+ Do not change its identity or gateway after resource reads.
45
48
 
46
- def set_api_client(client: STIDApiClient):
47
- global _client
48
- _client = client
49
+ Raises:
50
+ TypeError: If client is not an STIDApiClient.
51
+ RuntimeError: If a different client is already registered or initialized.
52
+ """
53
+ _provider.set(client)
49
54
 
50
55
 
51
56
  def get_api_url() -> str:
@@ -82,9 +87,7 @@ def get_json(url: str, raise_for_status: bool = False) -> Any:
82
87
  return c.get_json(url=url)
83
88
 
84
89
 
85
- def get_json_dict(
86
- url: str, raise_for_status: bool = False
87
- ) -> Optional[Dict[str, Any]]:
90
+ def get_json_dict(url: str, raise_for_status: bool = False) -> Optional[Dict[str, Any]]:
88
91
  """Fetch JSON and return an object, or None for another response shape."""
89
92
  data = get_json(url, raise_for_status=raise_for_status)
90
93
  if data is None:
@@ -98,3 +101,16 @@ def get_json_list(url: str, raise_for_status: bool = False) -> List[Any]:
98
101
  if data is None:
99
102
  return []
100
103
  return data if isinstance(data, list) else []
104
+
105
+
106
+ def get_json_lists(
107
+ urls: List[str], raise_for_status: bool = False, max_workers: int = 4
108
+ ) -> List[List[Any]]:
109
+ """Fetch JSON arrays concurrently, preserving URL order."""
110
+ if not urls:
111
+ return []
112
+
113
+ client = get_api_client()
114
+ client.raise_for_status = raise_for_status
115
+ data = client.get_multiple_json(urls, max_workers=max_workers)
116
+ return [response if isinstance(response, list) else [] for response in data]
stidapi-1.4.5/PKG-INFO DELETED
@@ -1,56 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: stidapi
3
- Version: 1.4.5
4
- Summary: Python client for connecting to Equinor STIDapi
5
- Author: Åsmund Våge Fannemel
6
- Author-email: Åsmund Våge Fannemel <asmf@equinor.com>
7
- License-Expression: LicenseRef-Proprietary
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.10
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: Programming Language :: Python :: 3.12
12
- Classifier: Programming Language :: Python :: 3.13
13
- Classifier: Programming Language :: Python :: 3.14
14
- Requires-Dist: eq-api-connector>=1.2.0,<2
15
- Requires-Python: >=3.10, <4
16
- Project-URL: repository, https://github.com/equinor/STIDapi-python
17
- Description-Content-Type: text/markdown
18
-
19
- # STIDapi-python
20
- A simple wrapper package to interface Equinor [STIDapi](https://stidapi.equinor.com/) using python and get plant, system, tag and doc data.
21
-
22
-
23
- ## Use
24
-
25
- Try it out by running the [demo](examples/demo.py) or the sample code below.
26
-
27
- ```
28
- from stidapi import Plant, Tag, Doc
29
-
30
-
31
- p = Plant("JSV")
32
- t = p.search_tag("*20LIC*")
33
- t2 = Tag("JSV",t[0].no)
34
-
35
-
36
- d = t2.get_doc()
37
- d2 = p.get_doc(d[0].no)
38
- d3 = Doc(p.inst_code, d[0].no)
39
- ```
40
-
41
- ## Installing
42
-
43
- Install package from pypi using `pip install stidapi`
44
-
45
- ## Developing / testing
46
-
47
- Dependency manager uv is preferred for developers. Install with required packages for testing and coverage:
48
- `uv sync`
49
-
50
- Call `uv run pytest` to run tests.
51
-
52
- To generate coverage report run `uv run pytest --cov=stidapi tests/ --cov-report=xml`
53
-
54
- To compare coverage with master branch run
55
- `uv run diff-cover coverage.xml --compare-branch master`
56
-
stidapi-1.4.5/README.md DELETED
@@ -1,38 +0,0 @@
1
- # STIDapi-python
2
- A simple wrapper package to interface Equinor [STIDapi](https://stidapi.equinor.com/) using python and get plant, system, tag and doc data.
3
-
4
-
5
- ## Use
6
-
7
- Try it out by running the [demo](examples/demo.py) or the sample code below.
8
-
9
- ```
10
- from stidapi import Plant, Tag, Doc
11
-
12
-
13
- p = Plant("JSV")
14
- t = p.search_tag("*20LIC*")
15
- t2 = Tag("JSV",t[0].no)
16
-
17
-
18
- d = t2.get_doc()
19
- d2 = p.get_doc(d[0].no)
20
- d3 = Doc(p.inst_code, d[0].no)
21
- ```
22
-
23
- ## Installing
24
-
25
- Install package from pypi using `pip install stidapi`
26
-
27
- ## Developing / testing
28
-
29
- Dependency manager uv is preferred for developers. Install with required packages for testing and coverage:
30
- `uv sync`
31
-
32
- Call `uv run pytest` to run tests.
33
-
34
- To generate coverage report run `uv run pytest --cov=stidapi tests/ --cov-report=xml`
35
-
36
- To compare coverage with master branch run
37
- `uv run diff-cover coverage.xml --compare-branch master`
38
-
@@ -1,10 +0,0 @@
1
- import logging
2
-
3
- from .doc import Doc
4
- from .tag import Tag
5
- from .plant import Plant
6
- from .system import System
7
-
8
- __all__ = ["Doc", "Tag", "Plant", "System"]
9
-
10
- logging.getLogger(__name__).addHandler(logging.NullHandler())
File without changes
File without changes