tracktolib 0.36.0__tar.gz → 0.37.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.
- {tracktolib-0.36.0 → tracktolib-0.37.0}/PKG-INFO +1 -1
- {tracktolib-0.36.0 → tracktolib-0.37.0}/pyproject.toml +2 -2
- {tracktolib-0.36.0 → tracktolib-0.37.0}/setup.py +1 -1
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/pg/utils.py +9 -4
- {tracktolib-0.36.0 → tracktolib-0.37.0}/LICENSE +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/README.md +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/__init__.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/api.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/http.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/logs.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/pg/__init__.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/pg/query.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/pg_sync.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/pg_utils.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/s3/__init__.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/s3/minio.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/s3/s3.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/tests.py +0 -0
- {tracktolib-0.36.0 → tracktolib-0.37.0}/tracktolib/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "tracktolib"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.37.0"
|
|
4
4
|
description = "Utility library for python"
|
|
5
5
|
authors = ["Julien Brayere <julien.brayere@tracktor.fr>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -70,7 +70,7 @@ pythonPlatform = "Linux"
|
|
|
70
70
|
|
|
71
71
|
[tool.commitizen]
|
|
72
72
|
name = "cz_conventional_commits"
|
|
73
|
-
version = "0.
|
|
73
|
+
version = "0.37.0"
|
|
74
74
|
tag_format = "$version"
|
|
75
75
|
version_files = [
|
|
76
76
|
"pyproject.toml:version"
|
|
@@ -19,7 +19,7 @@ extras_require = \
|
|
|
19
19
|
|
|
20
20
|
setup_kwargs = {
|
|
21
21
|
'name': 'tracktolib',
|
|
22
|
-
'version': '0.
|
|
22
|
+
'version': '0.37.0',
|
|
23
23
|
'description': 'Utility library for python',
|
|
24
24
|
'long_description': "# Tracktolib\n\n[](https://pypi.python.org/pypi/tracktolib)\n[](https://pypi.python.org/pypi/tracktolib)\n[](https://app.circleci.com/pipelines/github/Tracktor/tracktolib?branch=master)\n\nUtility library for python\n\n# Installation\n\nYou can choose to not install all the dependencies by specifying\nthe [extra](https://python-poetry.org/docs/cli/#options-4) parameter such as:\n\n```bash\npoetry add tracktolib@latest -E pg-sync -E tests --group dev \n```\n\nHere we only install the utilities using `psycopg` (pg-sync) and `deepdiff` (tests) for the dev environment.\n\n# Utilities\n\n- **log**\n\nUtility functions for logging.\n\n```python\nimport logging\nfrom tracktolib.logs import init_logging\n\nlogger = logging.getLogger()\nformatter, stream_handler = init_logging(logger, 'json', version='0.0.1')\n```\n\n- **pg**\n\nUtility functions for [asyncpg](https://github.com/MagicStack/asyncpg)\n\n- **pg-sync**\n\nUtility functions based on psycopg such as `fetch_one`, `insert_many`, `fetch_count` ...\n\nTo use the functions, create a `Connection` using psycopg: `conn = psycopg2.connect()`\n\n*fetch_one*\n\n```python\nfrom pg.pg_sync import (\n insert_many, fetch_one, fetch_count, fetch_all\n)\n\ndata = [\n {'foo': 'bar', 'value': 1},\n {'foo': 'baz', 'value': 2}\n]\ninsert_many(conn, 'public.test', data) # Will insert the 2 dict\nquery = 'SELECT foo from public.test order by value asc'\nvalue = fetch_one(conn, query, required=True) # Will return {'foo': 'bar'}, raise an error is not found\nassert fetch_count(conn, 'public.test') == 2\nquery = 'SELECT * from public.test order by value asc'\nassert fetch_all(conn, query) == data\n\n```\n\n- **tests**\n\nUtility functions for testing\n\n- **s3-minio**\n\nUtility functions for [minio](https://min.io/docs/minio/linux/developers/python/API.html)\n\n- **s3**\n\nUtility functions for [aiobotocore](https://github.com/aio-libs/aiobotocore)\n\n- **logs**\n\nUtility functions to initialize the logging formatting and streams\n\n- **http**\n\nUtility functions using [httpx](https://www.python-httpx.org/)\n\n- **api**\n\nUtility functions using [fastapi](https://fastapi.tiangolo.com/)\n",
|
|
25
25
|
'author': 'Julien Brayere',
|
|
@@ -3,7 +3,7 @@ import datetime as dt
|
|
|
3
3
|
import functools
|
|
4
4
|
import logging
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import AsyncIterator,
|
|
6
|
+
from typing import AsyncIterator, Iterable, Sequence
|
|
7
7
|
from typing_extensions import LiteralString
|
|
8
8
|
from ..pg_utils import get_conflict_query
|
|
9
9
|
|
|
@@ -91,7 +91,10 @@ async def upsert_csv(conn: asyncpg.Connection,
|
|
|
91
91
|
chunk_size: int = 5_000,
|
|
92
92
|
show_progress: bool = False,
|
|
93
93
|
nb_lines: int | None = None,
|
|
94
|
-
on_conflict_keys: Iterable[LiteralString] | None = None
|
|
94
|
+
on_conflict_keys: Iterable[LiteralString] | None = None,
|
|
95
|
+
delimiter: str = ',',
|
|
96
|
+
col_names: Sequence[str] | None = None,
|
|
97
|
+
skip_header: bool = False):
|
|
95
98
|
infos = await get_table_infos(conn, schema, table)
|
|
96
99
|
|
|
97
100
|
on_conflict_str = 'ON CONFLICT DO NOTHING'
|
|
@@ -100,8 +103,10 @@ async def upsert_csv(conn: asyncpg.Connection,
|
|
|
100
103
|
update_keys=on_conflict_keys)
|
|
101
104
|
|
|
102
105
|
with csv_path.open('r') as f:
|
|
103
|
-
reader = csv.DictReader(f)
|
|
104
|
-
|
|
106
|
+
reader = csv.DictReader(f, delimiter=delimiter, fieldnames=col_names)
|
|
107
|
+
if skip_header:
|
|
108
|
+
next(reader)
|
|
109
|
+
_columns = col_names if col_names else [x.lower() for x in (reader.fieldnames or [])]
|
|
105
110
|
async with conn.transaction():
|
|
106
111
|
_tmp_table, _tmp_query, _insert_query = get_tmp_table_query(schema, table,
|
|
107
112
|
columns=infos.keys(),
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|