stidapi 1.4.5__tar.gz → 1.5.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stidapi
3
- Version: 1.4.5
3
+ Version: 1.5.0
4
4
  Summary: Python client for connecting to Equinor STIDapi
5
5
  Author: Åsmund Våge Fannemel
6
6
  Author-email: Åsmund Våge Fannemel <asmf@equinor.com>
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
12
12
  Classifier: Programming Language :: Python :: 3.13
13
13
  Classifier: Programming Language :: Python :: 3.14
14
- Requires-Dist: eq-api-connector>=1.2.0,<2
14
+ Requires-Dist: eq-api-connector>=1.3.0,<2
15
15
  Requires-Python: >=3.10, <4
16
16
  Project-URL: repository, https://github.com/equinor/STIDapi-python
17
17
  Description-Content-Type: text/markdown
@@ -30,18 +30,40 @@ from stidapi import Plant, Tag, Doc
30
30
 
31
31
  p = Plant("JSV")
32
32
  t = p.search_tag("*20LIC*")
33
- t2 = Tag("JSV",t[0].no)
33
+ tag_no = t[0].no
34
+ t2 = Tag("JSV", tag_no)
34
35
 
35
36
 
36
37
  d = t2.get_doc()
37
- d2 = p.get_doc(d[0].no)
38
- d3 = Doc(p.inst_code, d[0].no)
38
+ doc_no = d[0].no
39
+ d2 = p.get_doc(doc_no)
40
+ d3 = Doc(p.inst_code, doc_no)
39
41
  ```
40
42
 
41
43
  ## Installing
42
44
 
43
45
  Install package from pypi using `pip install stidapi`
44
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
+
45
67
  ## Developing / testing
46
68
 
47
69
  Dependency manager uv is preferred for developers. Install with required packages for testing and coverage:
@@ -49,6 +71,10 @@ Dependency manager uv is preferred for developers. Install with required package
49
71
 
50
72
  Call `uv run pytest` to run tests.
51
73
 
74
+ Run the offline client lifecycle tests with `uv run pytest -m ci`.
75
+ The remaining legacy tests are not classified by that marker and include live
76
+ STID calls requiring authorized access; the full suite is not CI-safe.
77
+
52
78
  To generate coverage report run `uv run pytest --cov=stidapi tests/ --cov-report=xml`
53
79
 
54
80
  To compare coverage with master branch run
@@ -0,0 +1,64 @@
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
+ ## Developing / testing
50
+
51
+ Dependency manager uv is preferred for developers. Install with required packages for testing and coverage:
52
+ `uv sync`
53
+
54
+ Call `uv run pytest` to run tests.
55
+
56
+ Run the offline client lifecycle tests with `uv run pytest -m ci`.
57
+ The remaining legacy tests are not classified by that marker and include live
58
+ STID calls requiring authorized access; the full suite is not CI-safe.
59
+
60
+ To generate coverage report run `uv run pytest --cov=stidapi tests/ --cov-report=xml`
61
+
62
+ To compare coverage with master branch run
63
+ `uv run diff-cover coverage.xml --compare-branch master`
64
+
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stidapi"
3
- version = "1.4.5"
3
+ version = "1.5.0"
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.0"
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
 
@@ -352,6 +352,7 @@ class Tag:
352
352
  value: str = "",
353
353
  inst_code: Optional[Union[str, List[str]]] = None,
354
354
  stop_first: bool = True,
355
+ max_workers: int = 4,
355
356
  ) -> List["Tag"]:
356
357
  """Get List of Tag objects by searching for additional fields
357
358
 
@@ -361,7 +362,8 @@ class Tag:
361
362
  inst_code: STID plant code, or list of codes, to limit search to.
362
363
  Defaults to empty which will search all.
363
364
  stop_first (boolean): Set to False to get matches from all provided inst_code,
364
- else will stop at first match. Defaults to False.
365
+ else will stop at the first matching installation. Defaults to True.
366
+ max_workers (int): Maximum concurrent installation searches. Defaults to 4.
365
367
 
366
368
  Returns:
367
369
  List[Tag): List of Tag objects
@@ -375,18 +377,34 @@ class Tag:
375
377
  if isinstance(inst_code, str):
376
378
  inst_code = [inst_code]
377
379
 
380
+ if max_workers < 1:
381
+ raise ValueError("max_workers must be at least 1")
382
+
383
+ inst_codes = list(inst_code)
378
384
  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
385
+ for start in range(0, len(inst_codes), max_workers):
386
+ codes = inst_codes[start : start + max_workers]
387
+ urls = [
388
+ u.build_url(
389
+ f"{code}/tag-additional-field/{field_name}",
390
+ {"searchValue": value, "noContentAs200": True},
383
391
  )
392
+ for code in codes
393
+ ]
394
+ try:
395
+ responses = u.get_json_lists(urls, max_workers=max_workers)
384
396
  except ValueError:
385
397
  continue
386
- if len(res_code) > 0:
387
- res.extend(res_code)
388
-
389
- if stop_first:
390
- break
398
+ for code, response in zip(codes, responses):
399
+ res_code = [
400
+ Tag(inst_code=code, tag_no=item["tagNo"], data=item)
401
+ for item in response
402
+ if isinstance(item, dict) and "tagNo" in item
403
+ ]
404
+ if res_code:
405
+ res.extend(res_code)
406
+
407
+ if stop_first:
408
+ return res
391
409
 
392
410
  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/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