tracktolib 0.61.2__py3-none-any.whl → 0.62.1__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.
- tracktolib/__init__.py +8 -0
- tracktolib/logs.py +6 -6
- tracktolib/pg/query.py +17 -5
- tracktolib/pg/utils.py +1 -1
- {tracktolib-0.61.2.dist-info → tracktolib-0.62.1.dist-info}/METADATA +16 -29
- {tracktolib-0.61.2.dist-info → tracktolib-0.62.1.dist-info}/RECORD +7 -8
- tracktolib-0.62.1.dist-info/WHEEL +4 -0
- tracktolib-0.61.2.dist-info/WHEEL +0 -4
- tracktolib-0.61.2.dist-info/licenses/LICENSE +0 -21
tracktolib/__init__.py
CHANGED
tracktolib/logs.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from typing import Literal, overload, Any, TypeGuard
|
|
3
2
|
from dataclasses import dataclass
|
|
3
|
+
from typing import Literal, overload, Any, TypeGuard
|
|
4
4
|
|
|
5
5
|
try:
|
|
6
6
|
from pythonjsonlogger.json import JsonFormatter
|
|
@@ -18,12 +18,12 @@ class CustomJsonFormatter(JsonFormatter):
|
|
|
18
18
|
self.version: str = version
|
|
19
19
|
super().__init__(*args, **kwargs)
|
|
20
20
|
|
|
21
|
-
def add_fields(self,
|
|
22
|
-
super(CustomJsonFormatter, self).add_fields(
|
|
21
|
+
def add_fields(self, log_data: dict[str, Any], record: logging.LogRecord, message_dict: dict[str, Any]):
|
|
22
|
+
super(CustomJsonFormatter, self).add_fields(log_data, record, message_dict)
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
if not
|
|
26
|
-
|
|
24
|
+
log_data.pop("color_message", None)
|
|
25
|
+
if not log_data.get("version"):
|
|
26
|
+
log_data["version"] = self.version
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
@overload
|
tracktolib/pg/query.py
CHANGED
|
@@ -217,7 +217,7 @@ def get_update_fields(
|
|
|
217
217
|
fields.append(
|
|
218
218
|
f"{_col} = ${_counter}"
|
|
219
219
|
if k not in _merge_keys
|
|
220
|
-
else f"{_col} = COALESCE(t.{_col}, JSONB_BUILD_OBJECT()) ||
|
|
220
|
+
else f"{_col} = COALESCE(t.{_col}, JSONB_BUILD_OBJECT()) || ${_counter}"
|
|
221
221
|
)
|
|
222
222
|
counter += 1
|
|
223
223
|
return ",\n".join(fields), values + where_values
|
|
@@ -225,10 +225,14 @@ def get_update_fields(
|
|
|
225
225
|
|
|
226
226
|
@dataclass
|
|
227
227
|
class PGUpdateQuery(PGQuery):
|
|
228
|
-
"""
|
|
229
|
-
|
|
228
|
+
"""
|
|
229
|
+
Postgresql UPDATE query generator
|
|
230
230
|
"""
|
|
231
231
|
|
|
232
|
+
"""
|
|
233
|
+
Value to start the arguments from:
|
|
234
|
+
For instance, with a value of 10, the first argument will be $11
|
|
235
|
+
"""
|
|
232
236
|
start_from: int | None = None
|
|
233
237
|
"""Keys to use for the WHERE clause. Theses fields will not be updated"""
|
|
234
238
|
where_keys: list[str] | None = None
|
|
@@ -239,6 +243,8 @@ class PGUpdateQuery(PGQuery):
|
|
|
239
243
|
return_keys: bool = False
|
|
240
244
|
"""Values to update using merge (like {}::jsonb || {}::jsonb)"""
|
|
241
245
|
merge_keys: list[str] | None = None
|
|
246
|
+
"""If True, the query is for many items and values will be a list of tuples"""
|
|
247
|
+
is_many: bool = False
|
|
242
248
|
|
|
243
249
|
_update_fields: str | None = field(init=False, default=None)
|
|
244
250
|
_values: list | None = field(init=False, default=None)
|
|
@@ -264,7 +270,7 @@ class PGUpdateQuery(PGQuery):
|
|
|
264
270
|
def values(self):
|
|
265
271
|
if not self._values:
|
|
266
272
|
raise ValueError("No values found")
|
|
267
|
-
if len(self.items) == 1:
|
|
273
|
+
if len(self.items) == 1 and not self.is_many:
|
|
268
274
|
return self._values
|
|
269
275
|
_where_keys = self.where_keys or []
|
|
270
276
|
_keys_not_where = [k for k in self.keys if k not in _where_keys]
|
|
@@ -516,7 +522,13 @@ async def update_many(
|
|
|
516
522
|
query_callback: QueryCallback[PGUpdateQuery] | None = None,
|
|
517
523
|
):
|
|
518
524
|
query = PGUpdateQuery(
|
|
519
|
-
table=table,
|
|
525
|
+
table=table,
|
|
526
|
+
items=items,
|
|
527
|
+
start_from=start_from,
|
|
528
|
+
where_keys=keys,
|
|
529
|
+
where=where,
|
|
530
|
+
merge_keys=merge_keys,
|
|
531
|
+
is_many=True,
|
|
520
532
|
)
|
|
521
533
|
if query_callback is not None:
|
|
522
534
|
query_callback(query)
|
tracktolib/pg/utils.py
CHANGED
|
@@ -130,7 +130,7 @@ async def upsert_csv(
|
|
|
130
130
|
|
|
131
131
|
missing_cols = set(_columns) - set(infos.keys())
|
|
132
132
|
if missing_cols:
|
|
133
|
-
raise ValueError(f
|
|
133
|
+
raise ValueError(f"Could not find the following columns in the table: {','.join(missing_cols)}")
|
|
134
134
|
|
|
135
135
|
async with conn.transaction():
|
|
136
136
|
_tmp_table, _tmp_query, _insert_query = get_tmp_table_query(
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tracktolib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.62.1
|
|
4
4
|
Summary: Utility library for python
|
|
5
|
-
License: MIT
|
|
6
|
-
License-File: LICENSE
|
|
7
5
|
Keywords: utility
|
|
8
|
-
Author: Julien Brayere
|
|
9
6
|
Author-email: julien.brayere@tracktor.fr
|
|
10
|
-
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
License-Expression: MIT
|
|
12
8
|
Classifier: Operating System :: OS Independent
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
Requires-Dist: fastapi>=0.103.2 ; extra == 'api'
|
|
10
|
+
Requires-Dist: pydantic>=2 ; extra == 'api'
|
|
11
|
+
Requires-Dist: httpx>=0.25.0 ; extra == 'http'
|
|
12
|
+
Requires-Dist: python-json-logger>=3.2.1 ; extra == 'logs'
|
|
13
|
+
Requires-Dist: asyncpg>=0.27.0 ; extra == 'pg'
|
|
14
|
+
Requires-Dist: rich>=13.6.0 ; extra == 'pg'
|
|
15
|
+
Requires-Dist: psycopg>=3.1.12 ; extra == 'pg-sync'
|
|
16
|
+
Requires-Dist: aiobotocore>=2.9.0 ; extra == 's3'
|
|
17
|
+
Requires-Dist: minio>=7.2.0 ; extra == 's3-minio'
|
|
18
|
+
Requires-Dist: pycryptodome>=3.20.0 ; extra == 's3-minio'
|
|
19
|
+
Requires-Dist: deepdiff>=8.1.0 ; extra == 'tests'
|
|
20
|
+
Requires-Python: >=3.12, <4.0
|
|
17
21
|
Provides-Extra: api
|
|
18
22
|
Provides-Extra: http
|
|
19
23
|
Provides-Extra: logs
|
|
@@ -22,19 +26,6 @@ Provides-Extra: pg-sync
|
|
|
22
26
|
Provides-Extra: s3
|
|
23
27
|
Provides-Extra: s3-minio
|
|
24
28
|
Provides-Extra: tests
|
|
25
|
-
Requires-Dist: aiobotocore (>=2.9.0) ; extra == "s3"
|
|
26
|
-
Requires-Dist: asyncpg (>=0.27.0) ; extra == "pg"
|
|
27
|
-
Requires-Dist: deepdiff (>=8.1.0) ; extra == "tests"
|
|
28
|
-
Requires-Dist: fastapi (>=0.103.2) ; extra == "api"
|
|
29
|
-
Requires-Dist: httpx (>=0.25.0) ; extra == "http"
|
|
30
|
-
Requires-Dist: minio (>=7.2.0) ; extra == "s3-minio"
|
|
31
|
-
Requires-Dist: psycopg (>=3.1.12) ; extra == "pg-sync"
|
|
32
|
-
Requires-Dist: pycryptodome (>=3.20.0) ; extra == "s3-minio"
|
|
33
|
-
Requires-Dist: pydantic (>=2) ; extra == "api"
|
|
34
|
-
Requires-Dist: python-json-logger (>=3.2.1) ; extra == "logs"
|
|
35
|
-
Requires-Dist: rich (>=13.6.0) ; extra == "pg"
|
|
36
|
-
Project-URL: Homepage, https://github.com/tracktor/tracktolib
|
|
37
|
-
Project-URL: Repository, https://github.com/tracktor/tracktolib
|
|
38
29
|
Description-Content-Type: text/markdown
|
|
39
30
|
|
|
40
31
|
# Tracktolib
|
|
@@ -47,15 +38,12 @@ Utility library for python
|
|
|
47
38
|
|
|
48
39
|
# Installation
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
the [extra](https://python-poetry.org/docs/cli/#options-4) parameter such as:
|
|
41
|
+
Just run:
|
|
52
42
|
|
|
53
43
|
```bash
|
|
54
|
-
|
|
44
|
+
uv add tracktolib@latest
|
|
55
45
|
```
|
|
56
46
|
|
|
57
|
-
Here we only install the utilities using `psycopg` (pg-sync) and `deepdiff` (tests) for the dev environment.
|
|
58
|
-
|
|
59
47
|
# Utilities
|
|
60
48
|
|
|
61
49
|
- **log**
|
|
@@ -123,4 +111,3 @@ Utility functions using [httpx](https://www.python-httpx.org/)
|
|
|
123
111
|
- **api**
|
|
124
112
|
|
|
125
113
|
Utility functions using [fastapi](https://fastapi.tiangolo.com/)
|
|
126
|
-
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
tracktolib/__init__.py,sha256=
|
|
1
|
+
tracktolib/__init__.py,sha256=Q9d6h2lNjcYzxvfJ3zlNcpiP_Ak0T3TBPWINzZNrhu0,173
|
|
2
2
|
tracktolib/api.py,sha256=ZLMgjH3Y8r3MpXc8m3IuZbzTj3fgrZKZORtSVgbuP-M,10221
|
|
3
3
|
tracktolib/http_utils.py,sha256=c10JGmHaBw3VSDMYhz2dvVw2lo4PUAq1xMub74I7xDc,2625
|
|
4
|
-
tracktolib/logs.py,sha256=
|
|
4
|
+
tracktolib/logs.py,sha256=D2hx6urXl5l4PBGP8mCpcT4GX7tJeFfNY-7oBfHczBU,2191
|
|
5
5
|
tracktolib/pg/__init__.py,sha256=Ul_hgwvTXZvQBt7sHKi4ZI-0DDpnXmoFtmVkGRy-1J0,366
|
|
6
|
-
tracktolib/pg/query.py,sha256=
|
|
7
|
-
tracktolib/pg/utils.py,sha256=
|
|
6
|
+
tracktolib/pg/query.py,sha256=_wL9MQU_z8Sk0ZOYGVE0TjUbwBZ1OJJuEq2jlmWoeeM,16693
|
|
7
|
+
tracktolib/pg/utils.py,sha256=ygQn63EBDaEGB0p7P2ibellO2mv-StafanpXKcCUiZU,6324
|
|
8
8
|
tracktolib/pg_sync.py,sha256=MKDaV7dYsRy59Y0EE5RGZL0DlZ-RUdBeaN9eSBwiQJg,6718
|
|
9
9
|
tracktolib/pg_utils.py,sha256=ArYNdf9qsdYdzGEWmev8tZpyx8_1jaGGdkfYkauM7UM,2582
|
|
10
10
|
tracktolib/s3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -12,7 +12,6 @@ tracktolib/s3/minio.py,sha256=wMEjkSes9Fp39fD17IctALpD6zB2xwDRQEmO7Vzan3g,1387
|
|
|
12
12
|
tracktolib/s3/s3.py,sha256=0HbSAPoaup5-W4LK54zRCjrQ5mr8OWR-N9WjW99Q4aw,5937
|
|
13
13
|
tracktolib/tests.py,sha256=gKE--epQjgMZGXc5ydbl4zjOdmwztJS42UMV0p4hXEA,399
|
|
14
14
|
tracktolib/utils.py,sha256=ysTBF9V35fVXQVBPk0kfE_84SGRxzrayqmg9RbtoJq4,5761
|
|
15
|
-
tracktolib-0.
|
|
16
|
-
tracktolib-0.
|
|
17
|
-
tracktolib-0.
|
|
18
|
-
tracktolib-0.61.2.dist-info/RECORD,,
|
|
15
|
+
tracktolib-0.62.1.dist-info/WHEEL,sha256=3id4o64OvRm9dUknh3mMJNcfoTRK08ua5cU6DFyVy-4,79
|
|
16
|
+
tracktolib-0.62.1.dist-info/METADATA,sha256=dKxWZjdrwg0x4Hak-Wux5mQcjfT2ZL0in7ZQp_dyaXo,3053
|
|
17
|
+
tracktolib-0.62.1.dist-info/RECORD,,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Julien Brayere
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|