tracktolib 0.52.0__py3-none-any.whl → 0.54.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.
tracktolib/logs.py CHANGED
@@ -3,7 +3,7 @@ from typing import Literal, overload, Any, TypeGuard
3
3
  from dataclasses import dataclass
4
4
 
5
5
  try:
6
- from pythonjsonlogger import jsonlogger
6
+ from pythonjsonlogger.json import JsonFormatter
7
7
  except ImportError:
8
8
  raise ImportError('Please install pythonjsonlogger or tracktolib with "log" to use this module')
9
9
 
@@ -11,7 +11,7 @@ LogFormat = Literal["json", "console"]
11
11
 
12
12
 
13
13
  @dataclass
14
- class CustomJsonFormatter(jsonlogger.JsonFormatter):
14
+ class CustomJsonFormatter(JsonFormatter):
15
15
  version: str
16
16
 
17
17
  def __init__(self, version: str, *args, **kwargs):
tracktolib/pg_sync.py CHANGED
@@ -15,6 +15,21 @@ except ImportError:
15
15
  from .pg_utils import get_tmp_table_query
16
16
 
17
17
 
18
+ __all__ = (
19
+ "clean_tables",
20
+ "drop_db",
21
+ "fetch_all",
22
+ "fetch_count",
23
+ "fetch_one",
24
+ "get_insert_data",
25
+ "get_tables",
26
+ "insert_many",
27
+ "insert_one",
28
+ "insert_csv",
29
+ "set_seq_max",
30
+ )
31
+
32
+
18
33
  def fetch_all(engine: Connection, query: LiteralString, *data) -> list[dict]:
19
34
  with engine.cursor(row_factory=dict_row) as cur:
20
35
  resp = (cur.execute(query) if not data else cur.execute(query, data)).fetchall()
@@ -59,7 +74,7 @@ def _parse_value(v):
59
74
  return v
60
75
 
61
76
 
62
- def _get_insert_data(table: LiteralString, data: list[dict]) -> tuple[LiteralString, list[tuple[Any, ...]]]:
77
+ def get_insert_data(table: LiteralString, data: list[dict]) -> tuple[LiteralString, list[tuple[Any, ...]]]:
63
78
  keys = data[0].keys()
64
79
  _values = ",".join("%s" for _ in range(0, len(keys)))
65
80
  query = f"INSERT INTO {table} as t ({','.join(keys)}) VALUES ({_values})"
@@ -67,17 +82,37 @@ def _get_insert_data(table: LiteralString, data: list[dict]) -> tuple[LiteralStr
67
82
 
68
83
 
69
84
  def insert_many(engine: Connection, table: LiteralString, data: list[dict]):
70
- query, _data = _get_insert_data(table, data)
85
+ query, _data = get_insert_data(table, data)
71
86
  with engine.cursor() as cur:
72
87
  _ = cur.executemany(query, _data)
73
88
  engine.commit()
74
89
 
75
90
 
76
- def insert_one(engine: Connection, table: LiteralString, data: dict):
77
- query, _data = _get_insert_data(table, [data])
78
- with engine.cursor() as cur:
91
+ @overload
92
+ def insert_one(engine: Connection, table: LiteralString, data: dict, returning: None = None) -> None: ...
93
+
94
+
95
+ @overload
96
+ def insert_one(engine: Connection, table: LiteralString, data: dict, returning: list[LiteralString]) -> dict: ...
97
+
98
+
99
+ def insert_one(
100
+ engine: Connection, table: LiteralString, data: dict, returning: list[LiteralString] | None = None
101
+ ) -> dict | None:
102
+ query, _data = get_insert_data(table, [data])
103
+ _is_returning = False
104
+ if returning:
105
+ query = f"{query} RETURNING {','.join(returning)}"
106
+ _is_returning = True
107
+
108
+ with engine.cursor(row_factory=dict_row) as cur:
79
109
  _ = cur.execute(query, _data[0])
110
+ if _is_returning:
111
+ resp = cur.fetchone()
112
+ else:
113
+ resp = None
80
114
  engine.commit()
115
+ return resp
81
116
 
82
117
 
83
118
  def drop_db(conn: Connection, db_name: LiteralString):
tracktolib/s3/s3.py CHANGED
@@ -150,6 +150,7 @@ async def list_files(
150
150
  search_query: str | None = None,
151
151
  max_items: int | None = None,
152
152
  page_size: int | None = None,
153
+ starting_token: str | None = None,
153
154
  ) -> list[S3Item]:
154
155
  """
155
156
  See https://jmespath.org/ for the search query syntax.
@@ -158,9 +159,11 @@ async def list_files(
158
159
  paginator = client.get_paginator("list_objects")
159
160
  config = {}
160
161
  if max_items is not None:
161
- config["max_items"] = max_items
162
+ config["MaxItems"] = max_items
162
163
  if page_size is not None:
163
- config["page_size"] = page_size
164
+ config["PageSize"] = page_size
165
+ if starting_token is not None:
166
+ config["StartingToken"] = starting_token
164
167
 
165
168
  page_iterator = paginator.paginate(Bucket=bucket, Prefix=path, PaginationConfig=config if config else {})
166
169
  filtered_iterator = page_iterator.search(search_query) if search_query else page_iterator
tracktolib/tests.py CHANGED
@@ -2,7 +2,7 @@ import pprint
2
2
  from typing import Iterable
3
3
 
4
4
  try:
5
- import deepdiff
5
+ import deepdiff.diff as deepdiff
6
6
  except ImportError:
7
7
  raise ImportError('Please install deepdiff or tracktolib with "tests" to use this module')
8
8
 
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: tracktolib
3
- Version: 0.52.0
3
+ Version: 0.54.0
4
4
  Summary: Utility library for python
5
- Home-page: https://github.com/tracktor/tracktolib
6
5
  License: MIT
7
6
  Keywords: utility
8
7
  Author: Julien Brayere
@@ -23,15 +22,16 @@ Provides-Extra: s3-minio
23
22
  Provides-Extra: tests
24
23
  Requires-Dist: aiobotocore (>=2.9.0) ; extra == "s3"
25
24
  Requires-Dist: asyncpg (>=0.27.0) ; extra == "pg"
26
- Requires-Dist: deepdiff (>=6.6.0) ; extra == "tests"
25
+ Requires-Dist: deepdiff (>=8.1.0) ; extra == "tests"
27
26
  Requires-Dist: fastapi (>=0.103.2) ; extra == "api"
28
27
  Requires-Dist: httpx (>=0.25.0) ; extra == "http"
29
28
  Requires-Dist: minio (>=7.2.0) ; extra == "s3-minio"
30
29
  Requires-Dist: psycopg (>=3.1.12) ; extra == "pg-sync"
31
30
  Requires-Dist: pycryptodome (>=3.20.0) ; extra == "s3-minio"
32
31
  Requires-Dist: pydantic (>=2) ; extra == "api"
33
- Requires-Dist: python-json-logger (>=2.0.4) ; extra == "logs"
32
+ Requires-Dist: python-json-logger (>=3.2.1) ; extra == "logs"
34
33
  Requires-Dist: rich (>=13.6.0) ; extra == "pg"
34
+ Project-URL: Homepage, https://github.com/tracktor/tracktolib
35
35
  Project-URL: Repository, https://github.com/tracktor/tracktolib
36
36
  Description-Content-Type: text/markdown
37
37
 
@@ -1,19 +1,18 @@
1
- LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
2
1
  tracktolib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
2
  tracktolib/api.py,sha256=xArVgRj_g7bw2tEDbjC9qs9f55b9X0-kJoc8-s1rsYo,9616
4
3
  tracktolib/http_utils.py,sha256=c10JGmHaBw3VSDMYhz2dvVw2lo4PUAq1xMub74I7xDc,2625
5
- tracktolib/logs.py,sha256=M5RZ8OYKgLEBJeC1AwUCSRbFAH09hwdTjjs-AQ9QGg8,2204
4
+ tracktolib/logs.py,sha256=xgfRDnviZPr9qinSOgab8neIWPv9Rj2xzDHnIBvWQcU,2201
6
5
  tracktolib/pg/__init__.py,sha256=j67e3B3gBbCHLD20QBybptmNdbbVMzNhZE6XjIPuKVo,349
7
6
  tracktolib/pg/query.py,sha256=MBYOTL9aLnYRBhaLy8-P6uGNXOmyluejNyUdt3Gfx5M,14504
8
7
  tracktolib/pg/utils.py,sha256=cL24KEt4SWJQ7LJPzaO3c8Xg0ZLmjhn22DtTWg86nwc,6324
9
- tracktolib/pg_sync.py,sha256=z6EB0hELq6t129gnVnX0rNXv2McZXxI8khy-TEG65Ag,5165
8
+ tracktolib/pg_sync.py,sha256=QSvt5C92UTcc6EhtjrdUe6eDs7m9mIyBYclzQo9wKGQ,5959
10
9
  tracktolib/pg_utils.py,sha256=VXPpy1jGq6aCgTlfFJDIrq6JDujR83JN5ZRiCi8Lx4E,2582
11
10
  tracktolib/s3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
11
  tracktolib/s3/minio.py,sha256=wMEjkSes9Fp39fD17IctALpD6zB2xwDRQEmO7Vzan3g,1387
13
- tracktolib/s3/s3.py,sha256=I2fT3C9pIm9pM0V96O_wbYg_bPJX35ryzx05G3EgZus,5816
14
- tracktolib/tests.py,sha256=Pbc4yGQrIWFLBEgX-kDBxhMCqH-bfOJtkH2agvaM6ZQ,382
12
+ tracktolib/s3/s3.py,sha256=0HbSAPoaup5-W4LK54zRCjrQ5mr8OWR-N9WjW99Q4aw,5937
13
+ tracktolib/tests.py,sha256=gKE--epQjgMZGXc5ydbl4zjOdmwztJS42UMV0p4hXEA,399
15
14
  tracktolib/utils.py,sha256=ysTBF9V35fVXQVBPk0kfE_84SGRxzrayqmg9RbtoJq4,5761
16
- tracktolib-0.52.0.dist-info/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
17
- tracktolib-0.52.0.dist-info/METADATA,sha256=peqROd6d1t-a0mXJFJjgqy0mc7trrpLb8-l4nYANf5s,3692
18
- tracktolib-0.52.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
19
- tracktolib-0.52.0.dist-info/RECORD,,
15
+ tracktolib-0.54.0.dist-info/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
16
+ tracktolib-0.54.0.dist-info/METADATA,sha256=vGG2EzYa0cjUemdBQXkywKgVitQ1J6zbAWKsVrcjbL8,3704
17
+ tracktolib-0.54.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
18
+ tracktolib-0.54.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 2.0.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -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.
File without changes