python-databases 1.2.1__py3-none-any.whl → 1.2.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.
@@ -1,3 +1,3 @@
1
1
  from python_databases.consts import LOGGER_NAME
2
2
 
3
- ELK_LOGGER_NAME = f'{LOGGER_NAME}.elasticsearch'
3
+ ELK_LOGGER_NAME = f"{LOGGER_NAME}.elasticsearch"
@@ -63,7 +63,7 @@ class ElasticSearch(ABC):
63
63
  ) -> None:
64
64
  failed_response_list = []
65
65
  if failed_response := helpers.streaming_bulk(
66
- self.elk_client, list_of_docs, raise_on_error=False, request_timeout=request_timeout, chunk_size=1000
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)
@@ -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(self, data: list[dict], doc_index_name: str) -> list[dict]:
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
- self.logger.debug(f"index: {index + 1}/{len(data)}")
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
- self.logger.info(f"index: {i} - {i + chunk_size} / {len(list_of_docs)}")
166
- chunk = list_of_docs[i: i + chunk_size]
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(self, dataframe: pd.DataFrame) -> list:
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
- self.logger.debug(f"index: {index}/{len(dataframe_values)}")
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,3 +1,3 @@
1
1
  from python_databases.consts import LOGGER_NAME
2
2
 
3
- POSTGRESQL_LOGGER_NAME = f'{LOGGER_NAME}.postgresql'
3
+ POSTGRESQL_LOGGER_NAME = f"{LOGGER_NAME}.postgresql"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-databases
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: A Python library for managing and interacting with multiple databases seamlessly.
5
5
  Author: Avi Zaguri
6
6
  License: MIT
@@ -19,13 +19,9 @@ License-File: LICENSE
19
19
  Requires-Dist: custom-python-logger>=4.0.0
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
  ![PyPI version](https://img.shields.io/pypi/v/python-databases)
@@ -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=tW4jgeUsf3FhqEpNHZQr3SjqPbuJjcWQDsSqxAvUYPg,98
5
- python_databases/elasticsearch_infrastructure/elasticsearch.py,sha256=phbcAzM1HGXGl9AKk693IFNTrd7Mr1l-TSBsa8gvXbI,10756
4
+ python_databases/elasticsearch_infrastructure/consts.py,sha256=MBZL90yjYUmipayzj65-XEBS-4qTRhClGatnEwy7OfA,98
5
+ python_databases/elasticsearch_infrastructure/elasticsearch.py,sha256=KF4JlAwOL6EQ1Z3WTj5APTz1GfbyKLLqHZvbd3OsX_w,11064
6
6
  python_databases/postgresql_infrastructure/__init__.py,sha256=yBjq7SLnNgnxW0DCQHEwCi_FrCNtjsJGJXIq7XtkUZg,150
7
- python_databases/postgresql_infrastructure/consts.py,sha256=Fz19Qj-B9mPCTGInNygm2CPmY0nWiamWeEMrJsv-XB4,102
7
+ python_databases/postgresql_infrastructure/consts.py,sha256=1GPwiyRMyQJOgdz2np0H12cr9GrP9p3aR6APCli2Hs8,102
8
8
  python_databases/postgresql_infrastructure/postgresql.py,sha256=tFdQr5IOPYbuqKE3r9oqSoNoGMbED5NSEy1anrUNEyY,3105
9
- python_databases-1.2.1.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
10
- python_databases-1.2.1.dist-info/METADATA,sha256=VLnVd7qQ_6K7KfYhFA__fcI0Z55wNP-yGqQGFLbDkvM,2463
11
- python_databases-1.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
12
- python_databases-1.2.1.dist-info/top_level.txt,sha256=fXcMUntaYJfKeFS7FjQ6DY4WVXYBsgdrDmhOudYs-vg,17
13
- python_databases-1.2.1.dist-info/RECORD,,
9
+ python_databases-1.2.2.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
10
+ python_databases-1.2.2.dist-info/METADATA,sha256=JlYFc3Snud34rDVC4cMurZ34CPdYN7_uEidQFhe5Wqw,2338
11
+ python_databases-1.2.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
12
+ python_databases-1.2.2.dist-info/top_level.txt,sha256=fXcMUntaYJfKeFS7FjQ6DY4WVXYBsgdrDmhOudYs-vg,17
13
+ python_databases-1.2.2.dist-info/RECORD,,