python-databases 2.0.0__tar.gz → 2.2.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.
- {python_databases-2.0.0/python_databases.egg-info → python_databases-2.2.0}/PKG-INFO +5 -6
- {python_databases-2.0.0 → python_databases-2.2.0}/pyproject.toml +7 -10
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/elasticsearch_infrastructure/elasticsearch.py +14 -34
- {python_databases-2.0.0 → python_databases-2.2.0/python_databases.egg-info}/PKG-INFO +5 -6
- python_databases-2.2.0/python_databases.egg-info/requires.txt +5 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/tests/test_elasticsearch.py +0 -26
- python_databases-2.0.0/python_databases.egg-info/requires.txt +0 -6
- {python_databases-2.0.0 → python_databases-2.2.0}/LICENSE +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/MANIFEST.in +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/README.md +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/__init__.py +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/consts.py +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/elasticsearch_infrastructure/__init__.py +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/elasticsearch_infrastructure/consts.py +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/postgresql_infrastructure/__init__.py +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/postgresql_infrastructure/consts.py +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases/postgresql_infrastructure/postgresql.py +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases.egg-info/SOURCES.txt +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases.egg-info/dependency_links.txt +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/python_databases.egg-info/top_level.txt +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/setup.cfg +0 -0
- {python_databases-2.0.0 → python_databases-2.2.0}/tests/test_postgres.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-databases
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.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,11 +16,10 @@ 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
|
|
20
|
-
Requires-Dist: elasticsearch<9
|
|
21
|
-
Requires-Dist:
|
|
22
|
-
Requires-Dist:
|
|
23
|
-
Requires-Dist: python-dotenv>=1.2.1
|
|
19
|
+
Requires-Dist: custom-python-logger>=4.2.0
|
|
20
|
+
Requires-Dist: elasticsearch<9,>=8.19.3
|
|
21
|
+
Requires-Dist: psycopg2-binary>=2.9.13
|
|
22
|
+
Requires-Dist: python-dotenv>=1.2.4
|
|
24
23
|
Requires-Dist: retrying>=1.4.2
|
|
25
24
|
Dynamic: license-file
|
|
26
25
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-databases"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.2.0"
|
|
8
8
|
description = "A Python library for managing and interacting with multiple databases seamlessly."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -21,20 +21,17 @@ classifiers = [
|
|
|
21
21
|
]
|
|
22
22
|
|
|
23
23
|
dependencies = [
|
|
24
|
-
"custom-python-logger>=4.0
|
|
25
|
-
"elasticsearch
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"python-dotenv>=1.2.1",
|
|
24
|
+
"custom-python-logger>=4.2.0",
|
|
25
|
+
"elasticsearch>=8.19.3,<9",
|
|
26
|
+
"psycopg2-binary>=2.9.13",
|
|
27
|
+
"python-dotenv>=1.2.4",
|
|
29
28
|
"retrying>=1.4.2",
|
|
30
29
|
]
|
|
31
30
|
|
|
32
31
|
[dependency-groups]
|
|
33
32
|
dev = [
|
|
34
|
-
"pre-commit>=4.
|
|
35
|
-
"pytest>=9.0
|
|
36
|
-
"setuptools>=84.0.0",
|
|
37
|
-
"wheel>=0.48.0",
|
|
33
|
+
"pre-commit>=4.7.0",
|
|
34
|
+
"pytest>=9.2.0",
|
|
38
35
|
]
|
|
39
36
|
|
|
40
37
|
[project.urls]
|
|
@@ -6,7 +6,6 @@ from datetime import UTC, datetime
|
|
|
6
6
|
from enum import Enum
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
|
-
import pandas as pd
|
|
10
9
|
from custom_python_logger import get_logger
|
|
11
10
|
from elasticsearch import Elasticsearch, helpers
|
|
12
11
|
from retrying import retry
|
|
@@ -38,10 +37,10 @@ class ElasticSearch(ABC):
|
|
|
38
37
|
self.password = password
|
|
39
38
|
|
|
40
39
|
self.elasticsearch_port = elasticsearch_port
|
|
41
|
-
if
|
|
42
|
-
self.elasticsearch_url = f"{self.protocol.value}://{self.elk_hostname}"
|
|
43
|
-
else:
|
|
40
|
+
if self.elasticsearch_port:
|
|
44
41
|
self.elasticsearch_url = f"{self.protocol.value}://{self.elk_hostname}:{self.elasticsearch_port}"
|
|
42
|
+
else:
|
|
43
|
+
self.elasticsearch_url = f"{self.protocol.value}://{self.elk_hostname}"
|
|
45
44
|
self.kibana_port = kibana_port
|
|
46
45
|
|
|
47
46
|
self.elk_client = None
|
|
@@ -67,7 +66,7 @@ class ElasticSearch(ABC):
|
|
|
67
66
|
):
|
|
68
67
|
for item in failed_response:
|
|
69
68
|
if item[1]["index"]["status"] != 201 or item[1]["index"]["_shards"]["failed"] > 0:
|
|
70
|
-
self.logger.
|
|
69
|
+
self.logger.error(f"Failed document: \n{item}")
|
|
71
70
|
failed_response_list.append(item)
|
|
72
71
|
if raise_on_error and failed_response_list:
|
|
73
72
|
raise Exception(f"Failed to report {len(failed_response_list)} documents to Elasticsearch")
|
|
@@ -89,7 +88,9 @@ class ElasticSearch(ABC):
|
|
|
89
88
|
|
|
90
89
|
if quick:
|
|
91
90
|
self._set_list_of_docs_quick(
|
|
92
|
-
list_of_docs=list_of_docs,
|
|
91
|
+
list_of_docs=list_of_docs,
|
|
92
|
+
request_timeout=request_timeout,
|
|
93
|
+
raise_on_error=raise_on_error,
|
|
93
94
|
)
|
|
94
95
|
else:
|
|
95
96
|
self._set_list_of_docs_safe(list_of_docs=list_of_docs)
|
|
@@ -97,23 +98,15 @@ class ElasticSearch(ABC):
|
|
|
97
98
|
|
|
98
99
|
@staticmethod
|
|
99
100
|
def _get_doc_with_basic_info() -> dict:
|
|
100
|
-
doc = {}
|
|
101
|
-
|
|
102
101
|
timestamp = datetime.now(tz=UTC)
|
|
103
102
|
date_and_time_str = timestamp.isoformat()
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"date_and_time_str": date_and_time_str,
|
|
112
|
-
"date_str": date,
|
|
113
|
-
"time_str": time_part,
|
|
114
|
-
}
|
|
115
|
-
)
|
|
116
|
-
return doc
|
|
103
|
+
return {
|
|
104
|
+
"doc_id": timestamp.strftime("%Y%m%dT%H%M%S%f"),
|
|
105
|
+
"upload_timestamp": timestamp,
|
|
106
|
+
"date_and_time_str": date_and_time_str,
|
|
107
|
+
"date_str": date_and_time_str.split("T")[0],
|
|
108
|
+
"time_str": date_and_time_str.split("T")[1].split("+")[0],
|
|
109
|
+
}
|
|
117
110
|
|
|
118
111
|
@staticmethod
|
|
119
112
|
def _add_list_values_as_str(doc: dict, column: str, value: Any) -> None:
|
|
@@ -218,19 +211,6 @@ class ElasticSearch(ABC):
|
|
|
218
211
|
except Exception as e:
|
|
219
212
|
raise Exception(f"Failed to get documents from index '{index}': {str(e)}") from e
|
|
220
213
|
|
|
221
|
-
def convert_dataframes_to_list_of_docs(
|
|
222
|
-
self,
|
|
223
|
-
dataframe: pd.DataFrame,
|
|
224
|
-
log_progress: bool = False,
|
|
225
|
-
) -> list:
|
|
226
|
-
data = []
|
|
227
|
-
dataframe_values = dataframe.values.tolist()
|
|
228
|
-
for index, value in enumerate(dataframe_values):
|
|
229
|
-
if log_progress:
|
|
230
|
-
self.logger.debug(f"index: {index}/{len(dataframe_values)}")
|
|
231
|
-
data.append(value)
|
|
232
|
-
return data
|
|
233
|
-
|
|
234
214
|
|
|
235
215
|
class ElasticSearchOnPrem(ElasticSearch):
|
|
236
216
|
def __init__(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-databases
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.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,11 +16,10 @@ 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
|
|
20
|
-
Requires-Dist: elasticsearch<9
|
|
21
|
-
Requires-Dist:
|
|
22
|
-
Requires-Dist:
|
|
23
|
-
Requires-Dist: python-dotenv>=1.2.1
|
|
19
|
+
Requires-Dist: custom-python-logger>=4.2.0
|
|
20
|
+
Requires-Dist: elasticsearch<9,>=8.19.3
|
|
21
|
+
Requires-Dist: psycopg2-binary>=2.9.13
|
|
22
|
+
Requires-Dist: python-dotenv>=1.2.4
|
|
24
23
|
Requires-Dist: retrying>=1.4.2
|
|
25
24
|
Dynamic: license-file
|
|
26
25
|
|
|
@@ -10,7 +10,6 @@ from collections.abc import Iterator
|
|
|
10
10
|
from datetime import datetime
|
|
11
11
|
from unittest.mock import MagicMock, call, patch
|
|
12
12
|
|
|
13
|
-
import pandas as pd
|
|
14
13
|
import pytest
|
|
15
14
|
from elasticsearch.helpers import BulkIndexError
|
|
16
15
|
|
|
@@ -421,31 +420,6 @@ def test_get_documents_wraps_and_chains_client_error( # pylint: disable=redefin
|
|
|
421
420
|
assert exc_info.value.__cause__ is original, "original error not chained"
|
|
422
421
|
|
|
423
422
|
|
|
424
|
-
# --------------------------------------------------------------------------- #
|
|
425
|
-
# convert_dataframes_to_list_of_docs
|
|
426
|
-
# --------------------------------------------------------------------------- #
|
|
427
|
-
def test_convert_dataframes_returns_one_entry_per_row( # pylint: disable=redefined-outer-name
|
|
428
|
-
es: _FakeElasticSearch,
|
|
429
|
-
) -> None:
|
|
430
|
-
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
|
|
431
|
-
result = es.convert_dataframes_to_list_of_docs(dataframe=df)
|
|
432
|
-
assert len(result) == 2, f"expected one entry per row, got {result}"
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
@pytest.mark.xfail(
|
|
436
|
-
strict=True,
|
|
437
|
-
reason="BUG: convert_dataframes_to_list_of_docs returns bare value lists (df.values.tolist()), "
|
|
438
|
-
"dropping column names. Its output is not consumable by fill_elk_index_as_bulk / _build_document, "
|
|
439
|
-
"which iterate row.items().",
|
|
440
|
-
)
|
|
441
|
-
def test_convert_dataframes_output_is_keyed_by_column( # pylint: disable=redefined-outer-name
|
|
442
|
-
es: _FakeElasticSearch,
|
|
443
|
-
) -> None:
|
|
444
|
-
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
|
|
445
|
-
result = es.convert_dataframes_to_list_of_docs(dataframe=df)
|
|
446
|
-
assert result == [{"a": 1, "b": 3}, {"a": 2, "b": 4}], f"column names lost: {result}"
|
|
447
|
-
|
|
448
|
-
|
|
449
423
|
# --------------------------------------------------------------------------- #
|
|
450
424
|
# Concrete connect implementations
|
|
451
425
|
# --------------------------------------------------------------------------- #
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_databases-2.0.0 → python_databases-2.2.0}/python_databases.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|