etlplus 0.10.4__py3-none-any.whl → 0.11.11__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.
etlplus/file/gz.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.gz` module.
3
+
4
+ Stub helpers for GZ read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read GZ content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the GZ file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ GZ :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('GZ read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to GZ at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the GZ file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ GZ :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('GZ write is not implemented yet')
etlplus/file/json.py ADDED
@@ -0,0 +1,87 @@
1
+ """
2
+ :mod:`etlplus.file.json` module.
3
+
4
+ JSON read/write helpers.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ from pathlib import Path
11
+ from typing import cast
12
+
13
+ from ..types import JSONData
14
+ from ..types import JSONDict
15
+ from ..types import JSONList
16
+ from ..utils import count_records
17
+
18
+ # SECTION: FUNCTIONS ======================================================== #
19
+
20
+
21
+ def read(
22
+ path: Path,
23
+ ) -> JSONData:
24
+ """
25
+ Load and validate JSON payloads from ``path``.
26
+
27
+ Parameters
28
+ ----------
29
+ path : Path
30
+ Path to the JSON file on disk.
31
+
32
+ Returns
33
+ -------
34
+ JSONData
35
+ The structured data read from the JSON file.
36
+
37
+ Raises
38
+ ------
39
+ TypeError
40
+ If the JSON root is not an object or an array of objects.
41
+ """
42
+ with path.open('r', encoding='utf-8') as handle:
43
+ loaded = json.load(handle)
44
+
45
+ if isinstance(loaded, dict):
46
+ return cast(JSONDict, loaded)
47
+ if isinstance(loaded, list):
48
+ if all(isinstance(item, dict) for item in loaded):
49
+ return cast(JSONList, loaded)
50
+ raise TypeError(
51
+ 'JSON array must contain only objects (dicts) when loading file',
52
+ )
53
+ raise TypeError(
54
+ 'JSON root must be an object or an array of objects when loading file',
55
+ )
56
+
57
+
58
+ def write(
59
+ path: Path,
60
+ data: JSONData,
61
+ ) -> int:
62
+ """
63
+ Write ``data`` as formatted JSON to ``path``.
64
+
65
+ Parameters
66
+ ----------
67
+ path : Path
68
+ Path to the JSON file on disk.
69
+ data : JSONData
70
+ Data to serialize as JSON.
71
+
72
+ Returns
73
+ -------
74
+ int
75
+ The number of records written to the JSON file.
76
+ """
77
+ path.parent.mkdir(parents=True, exist_ok=True)
78
+ with path.open('w', encoding='utf-8') as handle:
79
+ json.dump(
80
+ data,
81
+ handle,
82
+ indent=2,
83
+ ensure_ascii=False,
84
+ )
85
+ handle.write('\n')
86
+
87
+ return count_records(data)
etlplus/file/ndjson.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.ndjson` module.
3
+
4
+ Stub helpers for NDJSON read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read NDJSON content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the NDJSON file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ NDJSON :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('NDJSON read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to NDJSON at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the NDJSON file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ NDJSON :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('NDJSON write is not implemented yet')
etlplus/file/orc.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.orc` module.
3
+
4
+ Stub helpers for ORC read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read ORC content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the ORC file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ ORC :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('ORC read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to ORC at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the ORC file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ ORC :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('ORC write is not implemented yet')
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.parquet` module.
3
+
4
+ Stub helpers for PARQUET read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read PARQUET content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the PARQUET file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ PARQUET :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('PARQUET read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to PARQUET at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the PARQUET file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ PARQUET :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('PARQUET write is not implemented yet')
etlplus/file/tsv.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.tsv` module.
3
+
4
+ Stub helpers for TSV read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read TSV content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the TSV file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ TSV :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('TSV read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to TSV at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the TSV file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ TSV :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('TSV write is not implemented yet')
etlplus/file/txt.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.txt` module.
3
+
4
+ Stub helpers for TXT read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read TXT content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the TXT file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ TXT :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('TXT read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to TXT at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the TXT file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ TXT :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('TXT write is not implemented yet')
etlplus/file/xls.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.xls` module.
3
+
4
+ Stub helpers for XLS read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read XLS content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the XLS file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ XLS :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('XLS read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to XLS at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the XLS file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ XLS :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('XLS write is not implemented yet')
etlplus/file/xlsx.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ :mod:`etlplus.file.xlsx` module.
3
+
4
+ Stub helpers for XLSX read/write.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from ..types import JSONData
12
+
13
+ # SECTION: EXPORTS ========================================================== #
14
+
15
+
16
+ def read(path: Path) -> JSONData:
17
+ """
18
+ Read XLSX content from ``path``.
19
+
20
+ Parameters
21
+ ----------
22
+ path : Path
23
+ Path to the XLSX file on disk.
24
+
25
+ Returns
26
+ -------
27
+ JSONData
28
+ Parsed payload.
29
+
30
+ Raises
31
+ ------
32
+ NotImplementedError
33
+ XLSX :func:`read` is not implemented yet.
34
+ """
35
+ raise NotImplementedError('XLSX read is not implemented yet')
36
+
37
+
38
+ def write(path: Path, data: JSONData) -> int:
39
+ """
40
+ Write ``data`` to XLSX at ``path``.
41
+
42
+ Parameters
43
+ ----------
44
+ path : Path
45
+ Path to the XLSX file on disk.
46
+ data : JSONData
47
+ Data to write.
48
+
49
+ Returns
50
+ -------
51
+ int
52
+ Number of records written.
53
+
54
+ Raises
55
+ ------
56
+ NotImplementedError
57
+ XLSX :func:`write` is not implemented yet.
58
+ """
59
+ raise NotImplementedError('XLSX write is not implemented yet')