python-databases 1.0.0__tar.gz → 1.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-1.0.0/python_databases.egg-info → python_databases-1.2.0}/PKG-INFO +4 -4
- {python_databases-1.0.0 → python_databases-1.2.0}/pyproject.toml +4 -4
- python_databases-1.2.0/python_databases/consts.py +1 -0
- python_databases-1.2.0/python_databases/elasticsearch_infrastructure/consts.py +3 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases/elasticsearch_infrastructure/elasticsearch.py +44 -11
- python_databases-1.2.0/python_databases/postgresql_infrastructure/consts.py +3 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases/postgresql_infrastructure/postgresql.py +3 -1
- {python_databases-1.0.0 → python_databases-1.2.0/python_databases.egg-info}/PKG-INFO +4 -4
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases.egg-info/SOURCES.txt +3 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases.egg-info/requires.txt +1 -1
- {python_databases-1.0.0 → python_databases-1.2.0}/LICENSE +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/MANIFEST.in +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/README.md +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases/__init__.py +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases/elasticsearch_infrastructure/__init__.py +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases/postgresql_infrastructure/__init__.py +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases.egg-info/dependency_links.txt +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/python_databases.egg-info/top_level.txt +0 -0
- {python_databases-1.0.0 → python_databases-1.2.0}/setup.cfg +0 -0
- {python_databases-1.0.0 → python_databases-1.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: 1.
|
|
3
|
+
Version: 1.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
|
|
@@ -10,13 +10,13 @@ Project-URL: Issues, https://github.com/aviz92/python-databases/issues
|
|
|
10
10
|
Keywords: development,databases,ORM,SQL,NoSQL,database management
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Topic :: System :: Logging
|
|
16
|
-
Requires-Python: >=3.
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: custom-python-logger>=
|
|
19
|
+
Requires-Dist: custom-python-logger>=4.0.0
|
|
20
20
|
Requires-Dist: elasticsearch<9
|
|
21
21
|
Requires-Dist: pandas>=2.3.3
|
|
22
22
|
Requires-Dist: pre-commit>=4.5.0
|
|
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-databases"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.2.0"
|
|
8
8
|
description = "A Python library for managing and interacting with multiple databases seamlessly."
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
11
|
license = { text = "MIT" }
|
|
12
12
|
authors = [{ name = "Avi Zaguri" },]
|
|
13
13
|
keywords = ["development", "databases", "ORM", "SQL", "NoSQL", "database management"]
|
|
@@ -15,13 +15,13 @@ keywords = ["development", "databases", "ORM", "SQL", "NoSQL", "database managem
|
|
|
15
15
|
classifiers = [
|
|
16
16
|
"Development Status :: 4 - Beta",
|
|
17
17
|
"Intended Audience :: Developers",
|
|
18
|
-
"Programming Language :: Python :: 3.
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
19
|
"Operating System :: OS Independent",
|
|
20
20
|
"Topic :: System :: Logging",
|
|
21
21
|
]
|
|
22
22
|
|
|
23
23
|
dependencies = [
|
|
24
|
-
"custom-python-logger>=
|
|
24
|
+
"custom-python-logger>=4.0.0",
|
|
25
25
|
"elasticsearch<9",
|
|
26
26
|
"pandas>=2.3.3",
|
|
27
27
|
"pre-commit>=4.5.0",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
LOGGER_NAME = "python_databases"
|
|
@@ -11,6 +11,8 @@ from custom_python_logger import get_logger
|
|
|
11
11
|
from elasticsearch import Elasticsearch, helpers
|
|
12
12
|
from retrying import retry
|
|
13
13
|
|
|
14
|
+
from python_databases.elasticsearch_infrastructure.consts import ELK_LOGGER_NAME
|
|
15
|
+
|
|
14
16
|
|
|
15
17
|
class UrlProtocol(Enum):
|
|
16
18
|
HTTP = "http"
|
|
@@ -27,7 +29,7 @@ class ElasticSearch(ABC):
|
|
|
27
29
|
username: str | None,
|
|
28
30
|
password: str | None,
|
|
29
31
|
) -> None:
|
|
30
|
-
self.logger = get_logger(
|
|
32
|
+
self.logger = get_logger(ELK_LOGGER_NAME)
|
|
31
33
|
self._change_elasticsearch_logger()
|
|
32
34
|
|
|
33
35
|
self.protocol = protocol
|
|
@@ -53,13 +55,22 @@ class ElasticSearch(ABC):
|
|
|
53
55
|
tracer = get_logger("elasticsearch")
|
|
54
56
|
tracer.setLevel(debug_level)
|
|
55
57
|
|
|
56
|
-
def _set_list_of_docs_quick(
|
|
58
|
+
def _set_list_of_docs_quick(
|
|
59
|
+
self,
|
|
60
|
+
list_of_docs: list[dict],
|
|
61
|
+
request_timeout: int = 600,
|
|
62
|
+
raise_on_error: bool = False,
|
|
63
|
+
) -> None:
|
|
64
|
+
failed_response_list = []
|
|
57
65
|
if failed_response := helpers.streaming_bulk(
|
|
58
|
-
|
|
66
|
+
self.elk_client, list_of_docs, raise_on_error=False, request_timeout=request_timeout, chunk_size=1000
|
|
59
67
|
):
|
|
60
68
|
for item in failed_response:
|
|
61
69
|
if item[1]["index"]["status"] != 201 or item[1]["index"]["_shards"]["failed"] > 0:
|
|
62
70
|
self.logger.debug(f"Failed document: \n{item}")
|
|
71
|
+
failed_response_list.append(item)
|
|
72
|
+
if raise_on_error and failed_response_list:
|
|
73
|
+
raise Exception(f"Failed to report {len(failed_response_list)} documents")
|
|
63
74
|
|
|
64
75
|
def _set_list_of_docs_safe(self, list_of_docs: list[dict]) -> None:
|
|
65
76
|
success_response, failed_response = helpers.bulk(self.elk_client, list_of_docs)
|
|
@@ -71,11 +82,21 @@ class ElasticSearch(ABC):
|
|
|
71
82
|
f"The documents that were not reported successfully: {failed_response}"
|
|
72
83
|
)
|
|
73
84
|
|
|
74
|
-
def post_list_of_docs(
|
|
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
|
|
91
|
+
) -> None:
|
|
75
92
|
self.logger.info("Start to report the documents to ELK")
|
|
76
93
|
|
|
77
94
|
if quick:
|
|
78
|
-
self._set_list_of_docs_quick(
|
|
95
|
+
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
|
|
99
|
+
)
|
|
79
100
|
else:
|
|
80
101
|
self._set_list_of_docs_safe(list_of_docs=list_of_docs)
|
|
81
102
|
self.logger.info("Finish to report the documents to ELK")
|
|
@@ -133,16 +154,27 @@ class ElasticSearch(ABC):
|
|
|
133
154
|
return list_of_docs
|
|
134
155
|
|
|
135
156
|
def post_list_of_docs_as_bulk_chunk(
|
|
136
|
-
self,
|
|
157
|
+
self,
|
|
158
|
+
list_of_docs: list[dict],
|
|
159
|
+
chunk_size: int = 1000,
|
|
160
|
+
time_sleep: int = 60,
|
|
161
|
+
quick: bool = False,
|
|
162
|
+
raise_on_error: bool = False,
|
|
137
163
|
) -> None:
|
|
138
164
|
for i in range(0, len(list_of_docs), chunk_size):
|
|
139
165
|
self.logger.info(f"index: {i} - {i + chunk_size} / {len(list_of_docs)}")
|
|
140
|
-
chunk = list_of_docs[i
|
|
141
|
-
self.post_list_of_docs(list_of_docs=chunk, quick=quick)
|
|
166
|
+
chunk = list_of_docs[i: i + chunk_size]
|
|
167
|
+
self.post_list_of_docs(list_of_docs=chunk, quick=quick, raise_on_error=raise_on_error)
|
|
142
168
|
time.sleep(time_sleep)
|
|
143
169
|
|
|
144
170
|
def fill_elk_index_as_bulk( # post_list_of_docs_as_bulk
|
|
145
|
-
self,
|
|
171
|
+
self,
|
|
172
|
+
data: list[dict],
|
|
173
|
+
doc_index_name: str,
|
|
174
|
+
chunk_size: int = 1000,
|
|
175
|
+
time_sleep: int = 1,
|
|
176
|
+
quick: bool = True,
|
|
177
|
+
raise_on_error: bool = False,
|
|
146
178
|
) -> None: # use as the main function to send data to the elastic search
|
|
147
179
|
list_of_docs = self._prepare_documents_for_bulk(
|
|
148
180
|
data=data,
|
|
@@ -154,6 +186,7 @@ class ElasticSearch(ABC):
|
|
|
154
186
|
chunk_size=chunk_size,
|
|
155
187
|
time_sleep=time_sleep,
|
|
156
188
|
quick=quick,
|
|
189
|
+
raise_on_error=raise_on_error,
|
|
157
190
|
)
|
|
158
191
|
|
|
159
192
|
def check_if_index_exists(self, index: str) -> bool:
|
|
@@ -208,7 +241,7 @@ class ElasticSearchOnPrem(ElasticSearch):
|
|
|
208
241
|
password=password,
|
|
209
242
|
)
|
|
210
243
|
|
|
211
|
-
self.logger = get_logger(
|
|
244
|
+
self.logger = get_logger(ELK_LOGGER_NAME)
|
|
212
245
|
|
|
213
246
|
self.connect_to_elasticsearch()
|
|
214
247
|
|
|
@@ -250,7 +283,7 @@ class ElasticSearchCloud(ElasticSearch):
|
|
|
250
283
|
password=password,
|
|
251
284
|
)
|
|
252
285
|
|
|
253
|
-
self.logger = get_logger(
|
|
286
|
+
self.logger = get_logger(ELK_LOGGER_NAME)
|
|
254
287
|
|
|
255
288
|
self.connect_to_elasticsearch()
|
|
256
289
|
|
|
@@ -6,6 +6,8 @@ import psycopg2
|
|
|
6
6
|
from custom_python_logger import get_logger
|
|
7
7
|
from psycopg2 import extras
|
|
8
8
|
|
|
9
|
+
from python_databases.postgresql_infrastructure.consts import POSTGRESQL_LOGGER_NAME
|
|
10
|
+
|
|
9
11
|
|
|
10
12
|
class PostgreSQL:
|
|
11
13
|
def __init__(
|
|
@@ -16,7 +18,7 @@ class PostgreSQL:
|
|
|
16
18
|
username: str | None = None,
|
|
17
19
|
password: str | None = None,
|
|
18
20
|
) -> None:
|
|
19
|
-
self.logger = get_logger(
|
|
21
|
+
self.logger = get_logger(POSTGRESQL_LOGGER_NAME)
|
|
20
22
|
|
|
21
23
|
self.name = name or os.getenv("POSTGRESQL_NAME")
|
|
22
24
|
self.host = host or os.getenv("POSTGRESQL_HOST")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-databases
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.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
|
|
@@ -10,13 +10,13 @@ Project-URL: Issues, https://github.com/aviz92/python-databases/issues
|
|
|
10
10
|
Keywords: development,databases,ORM,SQL,NoSQL,database management
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Topic :: System :: Logging
|
|
16
|
-
Requires-Python: >=3.
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: custom-python-logger>=
|
|
19
|
+
Requires-Dist: custom-python-logger>=4.0.0
|
|
20
20
|
Requires-Dist: elasticsearch<9
|
|
21
21
|
Requires-Dist: pandas>=2.3.3
|
|
22
22
|
Requires-Dist: pre-commit>=4.5.0
|
|
@@ -3,13 +3,16 @@ MANIFEST.in
|
|
|
3
3
|
README.md
|
|
4
4
|
pyproject.toml
|
|
5
5
|
python_databases/__init__.py
|
|
6
|
+
python_databases/consts.py
|
|
6
7
|
python_databases.egg-info/PKG-INFO
|
|
7
8
|
python_databases.egg-info/SOURCES.txt
|
|
8
9
|
python_databases.egg-info/dependency_links.txt
|
|
9
10
|
python_databases.egg-info/requires.txt
|
|
10
11
|
python_databases.egg-info/top_level.txt
|
|
11
12
|
python_databases/elasticsearch_infrastructure/__init__.py
|
|
13
|
+
python_databases/elasticsearch_infrastructure/consts.py
|
|
12
14
|
python_databases/elasticsearch_infrastructure/elasticsearch.py
|
|
13
15
|
python_databases/postgresql_infrastructure/__init__.py
|
|
16
|
+
python_databases/postgresql_infrastructure/consts.py
|
|
14
17
|
python_databases/postgresql_infrastructure/postgresql.py
|
|
15
18
|
tests/test_postgres.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_databases-1.0.0 → python_databases-1.2.0}/python_databases.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|