cognite-extractor-utils 7.0.0__py3-none-any.whl → 7.0.2__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 cognite-extractor-utils might be problematic. Click here for more details.

@@ -16,5 +16,5 @@
16
16
  Cognite extractor utils is a Python package that simplifies the development of new extractors.
17
17
  """
18
18
 
19
- __version__ = "7.0.0"
19
+ __version__ = "7.0.2"
20
20
  from .base import Extractor
@@ -85,10 +85,15 @@ Get a state store object as configured:
85
85
  However, all of these things will be automatically done for you if you are using the base Extractor class.
86
86
  """
87
87
 
88
+ from cognite.extractorutils.exceptions import InvalidConfigError
89
+
88
90
  from .elements import (
91
+ AuthenticatorConfig,
89
92
  BaseConfig,
93
+ CertificateConfig,
90
94
  CogniteConfig,
91
95
  ConfigType,
96
+ ConnectionConfig,
92
97
  EitherIdConfig,
93
98
  FileSizeConfig,
94
99
  LocalStateStoreConfig,
@@ -99,4 +104,4 @@ from .elements import (
99
104
  StateStoreConfig,
100
105
  TimeIntervalConfig,
101
106
  )
102
- from .loaders import ConfigResolver, load_yaml
107
+ from .loaders import ConfigResolver, KeyVaultAuthenticationMethod, KeyVaultLoader, load_yaml, load_yaml_dict
@@ -53,6 +53,10 @@ _logger = logging.getLogger(__name__)
53
53
 
54
54
  @dataclass
55
55
  class CertificateConfig:
56
+ """
57
+ Configuration parameters for certificates
58
+ """
59
+
56
60
  path: str
57
61
  password: Optional[str]
58
62
  authority_url: Optional[str] = None
@@ -94,6 +98,11 @@ class ConnectionConfig:
94
98
 
95
99
  @dataclass
96
100
  class EitherIdConfig:
101
+ """
102
+ Configuration parameter representing an ID in CDF, which can either be an external or internal ID.
103
+ An EitherId can only hold one ID type, not both.
104
+ """
105
+
97
106
  id: Optional[int]
98
107
  external_id: Optional[str]
99
108
 
@@ -103,6 +112,10 @@ class EitherIdConfig:
103
112
 
104
113
 
105
114
  class TimeIntervalConfig(yaml.YAMLObject):
115
+ """
116
+ Configuration parameter for setting a time interval
117
+ """
118
+
106
119
  def __init__(self, expression: str) -> None:
107
120
  self._interval, self._expression = TimeIntervalConfig._parse_expression(expression)
108
121
 
@@ -167,6 +180,10 @@ class TimeIntervalConfig(yaml.YAMLObject):
167
180
 
168
181
 
169
182
  class FileSizeConfig(yaml.YAMLObject):
183
+ """
184
+ Configuration parameter for setting a file size
185
+ """
186
+
170
187
  def __init__(self, expression: str) -> None:
171
188
  self._bytes, self._expression = FileSizeConfig._parse_expression(expression)
172
189
 
@@ -569,23 +586,39 @@ class BaseConfig(_BaseConfig):
569
586
 
570
587
  @dataclass
571
588
  class RawDestinationConfig:
589
+ """
590
+ Configuration parameters for using Raw
591
+ """
592
+
572
593
  database: str
573
594
  table: str
574
595
 
575
596
 
576
597
  @dataclass
577
598
  class RawStateStoreConfig(RawDestinationConfig):
599
+ """
600
+ Configuration of a state store based on CDF RAW
601
+ """
602
+
578
603
  upload_interval: TimeIntervalConfig = TimeIntervalConfig("30s")
579
604
 
580
605
 
581
606
  @dataclass
582
607
  class LocalStateStoreConfig:
608
+ """
609
+ Configuration of a state store using a local JSON file
610
+ """
611
+
583
612
  path: str
584
613
  save_interval: TimeIntervalConfig = TimeIntervalConfig("30s")
585
614
 
586
615
 
587
616
  @dataclass
588
617
  class StateStoreConfig:
618
+ """
619
+ Configuration of the State Store, containing ``LocalStateStoreConfig`` or ``RawStateStoreConfig``
620
+ """
621
+
589
622
  raw: Optional[RawStateStoreConfig] = None
590
623
  local: Optional[LocalStateStoreConfig] = None
591
624
 
@@ -47,6 +47,10 @@ class KeyVaultAuthenticationMethod(Enum):
47
47
 
48
48
 
49
49
  class KeyVaultLoader:
50
+ """
51
+ Class responsible for configuring keyvault for clients using Azure
52
+ """
53
+
50
54
  def __init__(self, config: Optional[dict]):
51
55
  self.config = config
52
56
 
@@ -15,7 +15,7 @@
15
15
 
16
16
  class InvalidConfigError(Exception):
17
17
  """
18
- Exception thrown from ``load_yaml`` if config file is invalid. This can be due to
18
+ Exception thrown from ``load_yaml`` and ``load_yaml_dict`` if config file is invalid. This can be due to
19
19
 
20
20
  * Missing fields
21
21
  * Incompatible types
@@ -1,6 +1,7 @@
1
1
  import logging
2
2
  import signal
3
3
  from threading import Condition
4
+ from time import time
4
5
  from typing import Any, Optional
5
6
 
6
7
 
@@ -59,11 +60,21 @@ class CancellationToken:
59
60
  self.cancel()
60
61
 
61
62
  def wait(self, timeout: Optional[float] = None) -> bool:
63
+ endtime = None
64
+ if timeout is not None:
65
+ endtime = time() + timeout
66
+
62
67
  while not self.is_cancelled:
63
68
  with self._cv:
64
- did_not_time_out = self._cv.wait(timeout)
65
- if not did_not_time_out:
66
- return False
69
+ if endtime is not None:
70
+ remaining_time = endtime - time()
71
+ if remaining_time <= 0.0:
72
+ return True
73
+ timed_out = not self._cv.wait(remaining_time)
74
+ if timed_out:
75
+ return False
76
+ else:
77
+ self._cv.wait()
67
78
  return True
68
79
 
69
80
  def create_child_token(self) -> "CancellationToken":
@@ -19,6 +19,8 @@ from os import PathLike
19
19
  from types import TracebackType
20
20
  from typing import Any, BinaryIO, Callable, Dict, List, Optional, Tuple, Type, Union
21
21
 
22
+ from requests.utils import super_len
23
+
22
24
  from cognite.client import CogniteClient
23
25
  from cognite.client.data_classes import FileMetadata
24
26
  from cognite.extractorutils.threading import CancellationToken
@@ -154,23 +156,34 @@ class IOFileUploadQueue(AbstractUploadQueue):
154
156
  try:
155
157
  # Upload file
156
158
  with read_file() as file:
157
- file_meta = self.cdf_client.files.upload_bytes(
158
- file,
159
- file_meta.name if file_meta.name is not None else "",
160
- overwrite=self.overwrite_existing,
161
- external_id=file_meta.external_id,
162
- source=file_meta.source,
163
- mime_type=file_meta.mime_type,
164
- metadata=file_meta.metadata,
165
- directory=file_meta.directory,
166
- asset_ids=file_meta.asset_ids,
167
- data_set_id=file_meta.data_set_id,
168
- labels=file_meta.labels,
169
- geo_location=file_meta.geo_location,
170
- source_created_time=file_meta.source_created_time,
171
- source_modified_time=file_meta.source_modified_time,
172
- security_categories=file_meta.security_categories,
173
- )
159
+ size = super_len(file)
160
+ if size == 0:
161
+ # upload just the file metadata witout data
162
+ file_meta, _url = self.cdf_client.files.create(
163
+ file_metadata=file_meta, overwrite=self.overwrite_existing
164
+ )
165
+ elif size > pow(5, 9):
166
+ # File bigger than 5Gb
167
+ self.logger.warning(f"File {file_meta.source} has more than 5Gb")
168
+ file_meta = FileMetadata()
169
+ else:
170
+ file_meta = self.cdf_client.files.upload_bytes(
171
+ file,
172
+ file_meta.name if file_meta.name is not None else "",
173
+ overwrite=self.overwrite_existing,
174
+ external_id=file_meta.external_id,
175
+ source=file_meta.source,
176
+ mime_type=file_meta.mime_type,
177
+ metadata=file_meta.metadata,
178
+ directory=file_meta.directory,
179
+ asset_ids=file_meta.asset_ids,
180
+ data_set_id=file_meta.data_set_id,
181
+ labels=file_meta.labels,
182
+ geo_location=file_meta.geo_location,
183
+ source_created_time=file_meta.source_created_time,
184
+ source_modified_time=file_meta.source_modified_time,
185
+ security_categories=file_meta.security_categories,
186
+ )
174
187
 
175
188
  if self.post_upload_function:
176
189
  try:
@@ -79,7 +79,7 @@ class EitherId:
79
79
 
80
80
  Args:
81
81
  id: Internal ID
82
- externalId or external_id: external ID
82
+ external_id: external ID. It can be `external_id` or `externalId`
83
83
 
84
84
  Raises:
85
85
  TypeError: If none of both of id types are set.
@@ -175,24 +175,25 @@ def add_extraction_pipeline(
175
175
  added_message: str = "",
176
176
  ) -> Callable[[Callable[..., _T1]], Callable[..., _T1]]:
177
177
  """
178
- This is to be used as a decorator for extractor functions to add extraction pipeline information
178
+ This is to be used as a decorator for extractor functions to add extraction pipeline information.
179
179
 
180
180
  Args:
181
- extraction_pipeline_ext_id:
182
- cognite_client:
183
- heartbeat_waiting_time:
184
- added_message:
181
+ extraction_pipeline_ext_id: External ID of the extraction pipeline
182
+ cognite_client: Client to use when communicating with CDF
183
+ heartbeat_waiting_time: Target interval between heartbeats, in seconds
185
184
 
186
185
  Usage:
187
186
  If you have a function named "extract_data(*args, **kwargs)" and want to connect it to an extraction
188
187
  pipeline, you can use this decorator function as:
189
- @add_extraction_pipeline(
190
- extraction_pipeline_ext_id=<INSERT EXTERNAL ID>,
191
- cognite_client=<INSERT COGNITE CLIENT OBJECT>,
192
- logger=<INSERT LOGGER>,
193
- )
194
- def extract_data(*args, **kwargs):
195
- <INSERT FUNCTION BODY>
188
+
189
+ .. code-block:: python
190
+
191
+ @add_extraction_pipeline(
192
+ extraction_pipeline_ext_id=<INSERT EXTERNAL ID>,
193
+ cognite_client=<INSERT COGNITE CLIENT OBJECT>,
194
+ )
195
+ def extract_data(*args, **kwargs):
196
+ <INSERT FUNCTION BODY>
196
197
  """
197
198
 
198
199
  # TODO 1. Consider refactoring this decorator to share methods with the Extractor context manager in .base.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cognite-extractor-utils
3
- Version: 7.0.0
3
+ Version: 7.0.2
4
4
  Summary: Utilities for easier development of extractors for CDF
5
5
  Home-page: https://github.com/cognitedata/python-extractor-utils
6
6
  License: Apache-2.0
@@ -1,27 +1,27 @@
1
- cognite/extractorutils/__init__.py,sha256=7RFWajf36G6iOaLnzGuuL3rDlIkt5L1GnsrgApS5-_8,739
1
+ cognite/extractorutils/__init__.py,sha256=2lG10jlln2GBVFsgvhjHFvBLyPUQgeESNNfejOuuRuU,739
2
2
  cognite/extractorutils/_inner_util.py,sha256=gmz6aqS7jDNsg8z4RHgJjMFohDLOMiaU4gMWBhg3xcE,1558
3
3
  cognite/extractorutils/base.py,sha256=o5oFzGBaszv7-HWMVG2ATmZwZfzi8enyrYIKwUagyCQ,16148
4
- cognite/extractorutils/configtools/__init__.py,sha256=fj9kH8DdisNi9mI8cKm2sz50vnzeOkJQErIGB3mTYRo,2861
4
+ cognite/extractorutils/configtools/__init__.py,sha256=L-daaqInIsmHcjb2forJeY0fW8tz1mlteOUo7IsWnrU,3059
5
5
  cognite/extractorutils/configtools/_util.py,sha256=SZycZm_py9v9WZbDiDQbgS6_PiLtu-TtwuuH7tG2YCI,4739
6
- cognite/extractorutils/configtools/elements.py,sha256=CM9ZVAUgy7DnbTGI_kgnNclioEkaUqv0Lt_a2zoS8Yc,20680
7
- cognite/extractorutils/configtools/loaders.py,sha256=Q062K-AFJLn9MjJaURar_Le79edGUZvvpgQdg9wm51I,15082
8
- cognite/extractorutils/exceptions.py,sha256=PERRmySUfJRM2Ta8cFvADTe-KUdXsoMLKdk4140AOHI,1061
6
+ cognite/extractorutils/configtools/elements.py,sha256=G9-2J-tzao4z5PfOpWifJCMgP7X7ABHK257NtrWsweI,21382
7
+ cognite/extractorutils/configtools/loaders.py,sha256=Y5UjJBXrYFcvjeGKvjWxc_7FW6PzKSIVVO3q8eNxPkA,15170
8
+ cognite/extractorutils/exceptions.py,sha256=XiwyNPSN0YxFYaPw7tfA63B94PL48xDK3EfdGdhgQgc,1084
9
9
  cognite/extractorutils/metrics.py,sha256=IzYevOH19N_Nhi2XfhcuGgsGfmF7SexfcHcTQyZmH1o,15635
10
10
  cognite/extractorutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  cognite/extractorutils/statestore.py,sha256=iJdVJQihjU2ljfS46FNEKdD5PSurTzaAH09iGbDYJro,18598
12
- cognite/extractorutils/threading.py,sha256=C77KgNZolI8E_xbv-G-BkJwLEALkkvZs5UoNx4hJiFg,3249
12
+ cognite/extractorutils/threading.py,sha256=2Hke5cFvP-wA45Crvh58JahoKXB64P3tr7R4y_BhBqM,3605
13
13
  cognite/extractorutils/uploader/__init__.py,sha256=W22u6QHA4cR0j78LN5LTL5YGbfC-uTApagTyP5ab7uQ,3110
14
14
  cognite/extractorutils/uploader/_base.py,sha256=-aFfoMSBGd9YUUMHL3ZQpLIuNMA7TNklWCEjPA18ER8,5282
15
15
  cognite/extractorutils/uploader/_metrics.py,sha256=J2LJXb19L_SLSJ_voNIQHYLp0pjxUKevpH1q_xKX6Hk,3247
16
16
  cognite/extractorutils/uploader/assets.py,sha256=2E90N1kxsaA6Ah4h0_r_dTVhDYY_68ItRWrHYkkltJw,5628
17
17
  cognite/extractorutils/uploader/events.py,sha256=NZP2tMoU_rh_rb-EZiUBsOT5KdNABHN4c9Oddk0OsdE,5680
18
- cognite/extractorutils/uploader/files.py,sha256=2BKwdgj2rlJqJWU-13ktCINdktI6IoKkeU2nAWUKOus,13176
18
+ cognite/extractorutils/uploader/files.py,sha256=A0HxmXLT6lK2QEZf-55Ma0FiisUl1a-VWxKF3SB07GM,13869
19
19
  cognite/extractorutils/uploader/raw.py,sha256=wFjF90PFTjmByOWx_Y4_YfDJ2w2jl0EQJ2Tjx2MP2PM,6738
20
20
  cognite/extractorutils/uploader/time_series.py,sha256=VptUq129MY0t8yw4rxeL0kOhz2dMibz4XdyvfhfYGj8,26840
21
21
  cognite/extractorutils/uploader_extractor.py,sha256=E-mpVvbPg_Tk90U4S9JybV0duptJ2SXE88HB6npE3zI,7732
22
22
  cognite/extractorutils/uploader_types.py,sha256=5MKT14DUnTFVD5Nx4Zvnfp2SfaICuTKLWAFAYaZishk,1045
23
- cognite/extractorutils/util.py,sha256=PFxVkDfpAEXTONYC1U-iO5DiaE3snn81qVUUT2O8xAM,17025
24
- cognite_extractor_utils-7.0.0.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
25
- cognite_extractor_utils-7.0.0.dist-info/METADATA,sha256=lSHI8N78-cWlmraTSSiHovCTL2P-4olyjpWLlwTwTD0,5437
26
- cognite_extractor_utils-7.0.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
27
- cognite_extractor_utils-7.0.0.dist-info/RECORD,,
23
+ cognite/extractorutils/util.py,sha256=1Atq4-N2Pyi6GrxMa1PEfMCTqhPiLb2YoUXTzd60Roc,17179
24
+ cognite_extractor_utils-7.0.2.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
25
+ cognite_extractor_utils-7.0.2.dist-info/METADATA,sha256=pE7JlOYLjX4ry0sfTGY-1uPgQ5c556g04Lqd8bXiCKg,5437
26
+ cognite_extractor_utils-7.0.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
27
+ cognite_extractor_utils-7.0.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any