python-databases 1.2.1__py3-none-any.whl → 2.0.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.
- python_databases/elasticsearch_infrastructure/consts.py +1 -1
- python_databases/elasticsearch_infrastructure/elasticsearch.py +26 -16
- python_databases/postgresql_infrastructure/consts.py +1 -1
- {python_databases-1.2.1.dist-info → python_databases-2.0.0.dist-info}/METADATA +2 -6
- {python_databases-1.2.1.dist-info → python_databases-2.0.0.dist-info}/RECORD +8 -8
- {python_databases-1.2.1.dist-info → python_databases-2.0.0.dist-info}/WHEEL +0 -0
- {python_databases-1.2.1.dist-info → python_databases-2.0.0.dist-info}/licenses/LICENSE +0 -0
- {python_databases-1.2.1.dist-info → python_databases-2.0.0.dist-info}/top_level.txt +0 -0
|
@@ -63,7 +63,7 @@ class ElasticSearch(ABC):
|
|
|
63
63
|
) -> None:
|
|
64
64
|
failed_response_list = []
|
|
65
65
|
if failed_response := helpers.streaming_bulk(
|
|
66
|
-
|
|
66
|
+
self.elk_client, list_of_docs, raise_on_error=False, request_timeout=request_timeout, chunk_size=1000
|
|
67
67
|
):
|
|
68
68
|
for item in failed_response:
|
|
69
69
|
if item[1]["index"]["status"] != 201 or item[1]["index"]["_shards"]["failed"] > 0:
|
|
@@ -83,19 +83,13 @@ class ElasticSearch(ABC):
|
|
|
83
83
|
)
|
|
84
84
|
|
|
85
85
|
def post_list_of_docs(
|
|
86
|
-
self,
|
|
87
|
-
list_of_docs: list[dict],
|
|
88
|
-
request_timeout: int = 600,
|
|
89
|
-
quick: bool = False,
|
|
90
|
-
raise_on_error: bool = False
|
|
86
|
+
self, list_of_docs: list[dict], request_timeout: int = 600, quick: bool = False, raise_on_error: bool = False
|
|
91
87
|
) -> None:
|
|
92
88
|
self.logger.info("Start to report the documents to ELK")
|
|
93
89
|
|
|
94
90
|
if quick:
|
|
95
91
|
self._set_list_of_docs_quick(
|
|
96
|
-
list_of_docs=list_of_docs,
|
|
97
|
-
request_timeout=request_timeout,
|
|
98
|
-
raise_on_error=raise_on_error
|
|
92
|
+
list_of_docs=list_of_docs, request_timeout=request_timeout, raise_on_error=raise_on_error
|
|
99
93
|
)
|
|
100
94
|
else:
|
|
101
95
|
self._set_list_of_docs_safe(list_of_docs=list_of_docs)
|
|
@@ -113,7 +107,7 @@ class ElasticSearch(ABC):
|
|
|
113
107
|
doc.update(
|
|
114
108
|
{
|
|
115
109
|
"doc_id": timestamp.strftime("%Y%m%dT%H%M%S%f"),
|
|
116
|
-
"
|
|
110
|
+
"upload_timestamp": timestamp,
|
|
117
111
|
"date_and_time_str": date_and_time_str,
|
|
118
112
|
"date_str": date,
|
|
119
113
|
"time_str": time_part,
|
|
@@ -145,10 +139,16 @@ class ElasticSearch(ABC):
|
|
|
145
139
|
def _fill_list_of_docs(index_name: str, doc: dict[str, Any]) -> dict:
|
|
146
140
|
return {"_index": index_name, "_source": deepcopy(doc)}
|
|
147
141
|
|
|
148
|
-
def _prepare_documents_for_bulk(
|
|
142
|
+
def _prepare_documents_for_bulk(
|
|
143
|
+
self,
|
|
144
|
+
data: list[dict],
|
|
145
|
+
doc_index_name: str,
|
|
146
|
+
log_progress: bool = False,
|
|
147
|
+
) -> list[dict]:
|
|
149
148
|
list_of_docs = []
|
|
150
149
|
for index, row in enumerate(data):
|
|
151
|
-
|
|
150
|
+
if log_progress:
|
|
151
|
+
self.logger.debug(f"index: {index + 1}/{len(data)}")
|
|
152
152
|
doc = self._build_document(row=row)
|
|
153
153
|
list_of_docs.append(self._fill_list_of_docs(index_name=doc_index_name, doc=doc))
|
|
154
154
|
return list_of_docs
|
|
@@ -160,10 +160,12 @@ class ElasticSearch(ABC):
|
|
|
160
160
|
time_sleep: int = 60,
|
|
161
161
|
quick: bool = False,
|
|
162
162
|
raise_on_error: bool = False,
|
|
163
|
+
log_progress: bool = False,
|
|
163
164
|
) -> None:
|
|
164
165
|
for i in range(0, len(list_of_docs), chunk_size):
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
if log_progress:
|
|
167
|
+
self.logger.info(f"index: {i} - {i + chunk_size} / {len(list_of_docs)}")
|
|
168
|
+
chunk = list_of_docs[i : i + chunk_size]
|
|
167
169
|
self.post_list_of_docs(list_of_docs=chunk, quick=quick, raise_on_error=raise_on_error)
|
|
168
170
|
time.sleep(time_sleep)
|
|
169
171
|
|
|
@@ -175,10 +177,12 @@ class ElasticSearch(ABC):
|
|
|
175
177
|
time_sleep: int = 1,
|
|
176
178
|
quick: bool = True,
|
|
177
179
|
raise_on_error: bool = False,
|
|
180
|
+
log_progress: bool = False,
|
|
178
181
|
) -> None: # use as the main function to send data to the elastic search
|
|
179
182
|
list_of_docs = self._prepare_documents_for_bulk(
|
|
180
183
|
data=data,
|
|
181
184
|
doc_index_name=doc_index_name,
|
|
185
|
+
log_progress=log_progress,
|
|
182
186
|
)
|
|
183
187
|
|
|
184
188
|
self.post_list_of_docs_as_bulk_chunk(
|
|
@@ -187,6 +191,7 @@ class ElasticSearch(ABC):
|
|
|
187
191
|
time_sleep=time_sleep,
|
|
188
192
|
quick=quick,
|
|
189
193
|
raise_on_error=raise_on_error,
|
|
194
|
+
log_progress=log_progress,
|
|
190
195
|
)
|
|
191
196
|
|
|
192
197
|
def check_if_index_exists(self, index: str) -> bool:
|
|
@@ -213,11 +218,16 @@ class ElasticSearch(ABC):
|
|
|
213
218
|
except Exception as e:
|
|
214
219
|
raise Exception(f"Failed to get documents from index '{index}': {str(e)}") from e
|
|
215
220
|
|
|
216
|
-
def convert_dataframes_to_list_of_docs(
|
|
221
|
+
def convert_dataframes_to_list_of_docs(
|
|
222
|
+
self,
|
|
223
|
+
dataframe: pd.DataFrame,
|
|
224
|
+
log_progress: bool = False,
|
|
225
|
+
) -> list:
|
|
217
226
|
data = []
|
|
218
227
|
dataframe_values = dataframe.values.tolist()
|
|
219
228
|
for index, value in enumerate(dataframe_values):
|
|
220
|
-
|
|
229
|
+
if log_progress:
|
|
230
|
+
self.logger.debug(f"index: {index}/{len(dataframe_values)}")
|
|
221
231
|
data.append(value)
|
|
222
232
|
return data
|
|
223
233
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-databases
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: A Python library for managing and interacting with multiple databases seamlessly.
|
|
5
5
|
Author: Avi Zaguri
|
|
6
6
|
License: MIT
|
|
@@ -16,16 +16,12 @@ Classifier: Topic :: System :: Logging
|
|
|
16
16
|
Requires-Python: >=3.12
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: custom-python-logger>=4.0.
|
|
19
|
+
Requires-Dist: custom-python-logger>=4.0.2
|
|
20
20
|
Requires-Dist: elasticsearch<9
|
|
21
21
|
Requires-Dist: pandas>=2.3.3
|
|
22
|
-
Requires-Dist: pre-commit>=4.5.0
|
|
23
22
|
Requires-Dist: psycopg2-binary>=2.9.11
|
|
24
|
-
Requires-Dist: pytest>=9.0.1
|
|
25
23
|
Requires-Dist: python-dotenv>=1.2.1
|
|
26
24
|
Requires-Dist: retrying>=1.4.2
|
|
27
|
-
Requires-Dist: setuptools>=80.9.0
|
|
28
|
-
Requires-Dist: wheel>=0.45.1
|
|
29
25
|
Dynamic: license-file
|
|
30
26
|
|
|
31
27
|

|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
python_databases/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
python_databases/consts.py,sha256=ADn3PmhTXKBobtiVgDR4Tqq2Ncn_FTK0WjgREOLdBPs,33
|
|
3
3
|
python_databases/elasticsearch_infrastructure/__init__.py,sha256=U1orkPi0Pg-1rtY1CPSF4-eVRfrMr36qpT9VNKjBUw4,297
|
|
4
|
-
python_databases/elasticsearch_infrastructure/consts.py,sha256=
|
|
5
|
-
python_databases/elasticsearch_infrastructure/elasticsearch.py,sha256=
|
|
4
|
+
python_databases/elasticsearch_infrastructure/consts.py,sha256=MBZL90yjYUmipayzj65-XEBS-4qTRhClGatnEwy7OfA,98
|
|
5
|
+
python_databases/elasticsearch_infrastructure/elasticsearch.py,sha256=GtWDvOpwoUCq6zvml6KFi9Xxlu34bKZTRZjZYlZmggw,11071
|
|
6
6
|
python_databases/postgresql_infrastructure/__init__.py,sha256=yBjq7SLnNgnxW0DCQHEwCi_FrCNtjsJGJXIq7XtkUZg,150
|
|
7
|
-
python_databases/postgresql_infrastructure/consts.py,sha256=
|
|
7
|
+
python_databases/postgresql_infrastructure/consts.py,sha256=1GPwiyRMyQJOgdz2np0H12cr9GrP9p3aR6APCli2Hs8,102
|
|
8
8
|
python_databases/postgresql_infrastructure/postgresql.py,sha256=tFdQr5IOPYbuqKE3r9oqSoNoGMbED5NSEy1anrUNEyY,3105
|
|
9
|
-
python_databases-
|
|
10
|
-
python_databases-
|
|
11
|
-
python_databases-
|
|
12
|
-
python_databases-
|
|
13
|
-
python_databases-
|
|
9
|
+
python_databases-2.0.0.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
|
|
10
|
+
python_databases-2.0.0.dist-info/METADATA,sha256=-lJYYQ9x82y0A5k1ISRlVTrMP8V8PKn3ml8niTaDfaY,2338
|
|
11
|
+
python_databases-2.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
12
|
+
python_databases-2.0.0.dist-info/top_level.txt,sha256=fXcMUntaYJfKeFS7FjQ6DY4WVXYBsgdrDmhOudYs-vg,17
|
|
13
|
+
python_databases-2.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|