etlplus 0.9.1__py3-none-any.whl → 0.9.2__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.
Files changed (120) hide show
  1. etlplus/README.md +37 -0
  2. etlplus/__init__.py +1 -26
  3. etlplus/api/README.md +51 -3
  4. etlplus/api/__init__.py +10 -0
  5. etlplus/api/config.py +39 -28
  6. etlplus/api/endpoint_client.py +3 -3
  7. etlplus/api/enums.py +51 -0
  8. etlplus/api/pagination/client.py +1 -1
  9. etlplus/api/rate_limiting/config.py +13 -1
  10. etlplus/api/rate_limiting/rate_limiter.py +8 -11
  11. etlplus/api/request_manager.py +11 -6
  12. etlplus/api/transport.py +14 -2
  13. etlplus/api/types.py +96 -6
  14. etlplus/{run_helpers.py → api/utils.py} +209 -153
  15. etlplus/cli/README.md +40 -0
  16. etlplus/cli/commands.py +76 -43
  17. etlplus/cli/constants.py +1 -1
  18. etlplus/cli/handlers.py +40 -12
  19. etlplus/cli/io.py +2 -2
  20. etlplus/cli/main.py +1 -1
  21. etlplus/cli/state.py +4 -7
  22. etlplus/database/README.md +48 -0
  23. etlplus/database/ddl.py +1 -1
  24. etlplus/database/engine.py +19 -3
  25. etlplus/database/orm.py +2 -0
  26. etlplus/database/schema.py +1 -1
  27. etlplus/enums.py +1 -157
  28. etlplus/file/README.md +105 -0
  29. etlplus/file/__init__.py +25 -0
  30. etlplus/file/_imports.py +141 -0
  31. etlplus/file/_io.py +160 -0
  32. etlplus/file/accdb.py +78 -0
  33. etlplus/file/arrow.py +78 -0
  34. etlplus/file/avro.py +176 -0
  35. etlplus/file/bson.py +77 -0
  36. etlplus/file/cbor.py +78 -0
  37. etlplus/file/cfg.py +79 -0
  38. etlplus/file/conf.py +80 -0
  39. etlplus/file/core.py +322 -0
  40. etlplus/file/csv.py +79 -0
  41. etlplus/file/dat.py +78 -0
  42. etlplus/file/dta.py +77 -0
  43. etlplus/file/duckdb.py +78 -0
  44. etlplus/file/enums.py +343 -0
  45. etlplus/file/feather.py +111 -0
  46. etlplus/file/fwf.py +77 -0
  47. etlplus/file/gz.py +123 -0
  48. etlplus/file/hbs.py +78 -0
  49. etlplus/file/hdf5.py +78 -0
  50. etlplus/file/ini.py +79 -0
  51. etlplus/file/ion.py +78 -0
  52. etlplus/file/jinja2.py +78 -0
  53. etlplus/file/json.py +98 -0
  54. etlplus/file/log.py +78 -0
  55. etlplus/file/mat.py +78 -0
  56. etlplus/file/mdb.py +78 -0
  57. etlplus/file/msgpack.py +78 -0
  58. etlplus/file/mustache.py +78 -0
  59. etlplus/file/nc.py +78 -0
  60. etlplus/file/ndjson.py +108 -0
  61. etlplus/file/numbers.py +75 -0
  62. etlplus/file/ods.py +79 -0
  63. etlplus/file/orc.py +111 -0
  64. etlplus/file/parquet.py +113 -0
  65. etlplus/file/pb.py +78 -0
  66. etlplus/file/pbf.py +77 -0
  67. etlplus/file/properties.py +78 -0
  68. etlplus/file/proto.py +77 -0
  69. etlplus/file/psv.py +79 -0
  70. etlplus/file/rda.py +78 -0
  71. etlplus/file/rds.py +78 -0
  72. etlplus/file/sas7bdat.py +78 -0
  73. etlplus/file/sav.py +77 -0
  74. etlplus/file/sqlite.py +78 -0
  75. etlplus/file/stub.py +84 -0
  76. etlplus/file/sylk.py +77 -0
  77. etlplus/file/tab.py +81 -0
  78. etlplus/file/toml.py +78 -0
  79. etlplus/file/tsv.py +80 -0
  80. etlplus/file/txt.py +102 -0
  81. etlplus/file/vm.py +78 -0
  82. etlplus/file/wks.py +77 -0
  83. etlplus/file/xls.py +88 -0
  84. etlplus/file/xlsm.py +79 -0
  85. etlplus/file/xlsx.py +99 -0
  86. etlplus/file/xml.py +185 -0
  87. etlplus/file/xpt.py +78 -0
  88. etlplus/file/yaml.py +95 -0
  89. etlplus/file/zip.py +175 -0
  90. etlplus/file/zsav.py +77 -0
  91. etlplus/ops/README.md +50 -0
  92. etlplus/ops/__init__.py +61 -0
  93. etlplus/{extract.py → ops/extract.py} +81 -99
  94. etlplus/{load.py → ops/load.py} +78 -101
  95. etlplus/{run.py → ops/run.py} +159 -127
  96. etlplus/{transform.py → ops/transform.py} +75 -68
  97. etlplus/{validation → ops}/utils.py +53 -17
  98. etlplus/{validate.py → ops/validate.py} +22 -12
  99. etlplus/templates/README.md +46 -0
  100. etlplus/types.py +5 -4
  101. etlplus/utils.py +136 -2
  102. etlplus/workflow/README.md +52 -0
  103. etlplus/{config → workflow}/__init__.py +10 -23
  104. etlplus/{config → workflow}/connector.py +58 -44
  105. etlplus/workflow/dag.py +105 -0
  106. etlplus/{config → workflow}/jobs.py +105 -32
  107. etlplus/{config → workflow}/pipeline.py +59 -51
  108. etlplus/{config → workflow}/profile.py +8 -5
  109. etlplus/workflow/types.py +115 -0
  110. {etlplus-0.9.1.dist-info → etlplus-0.9.2.dist-info}/METADATA +210 -17
  111. etlplus-0.9.2.dist-info/RECORD +134 -0
  112. {etlplus-0.9.1.dist-info → etlplus-0.9.2.dist-info}/WHEEL +1 -1
  113. etlplus/config/types.py +0 -204
  114. etlplus/config/utils.py +0 -120
  115. etlplus/file.py +0 -657
  116. etlplus/validation/__init__.py +0 -44
  117. etlplus-0.9.1.dist-info/RECORD +0 -65
  118. {etlplus-0.9.1.dist-info → etlplus-0.9.2.dist-info}/entry_points.txt +0 -0
  119. {etlplus-0.9.1.dist-info → etlplus-0.9.2.dist-info}/licenses/LICENSE +0 -0
  120. {etlplus-0.9.1.dist-info → etlplus-0.9.2.dist-info}/top_level.txt +0 -0
etlplus/file/avro.py ADDED
@@ -0,0 +1,176 @@
1
+ """
2
+ :mod:`etlplus.file.avro` module.
3
+
4
+ Helpers for reading/writing Apache Avro (AVRO) files.
5
+
6
+ Notes
7
+ -----
8
+ - An AVRO file is a binary file format designed for efficient
9
+ on-disk storage of data, with a schema definition.
10
+ - Common cases:
11
+ - Data serialization for distributed systems.
12
+ - Interoperability between different programming languages.
13
+ - Storage of large datasets with schema evolution support.
14
+ - Rule of thumb:
15
+ - If the file follows the Apache Avro specification, use this module for
16
+ reading and writing.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ from pathlib import Path
22
+ from typing import Any
23
+ from typing import cast
24
+
25
+ from etlplus.file._imports import get_fastavro
26
+
27
+ from ..types import JSONData
28
+ from ..types import JSONDict
29
+ from ..types import JSONList
30
+ from ._io import normalize_records
31
+
32
+ # SECTION: EXPORTS ========================================================== #
33
+
34
+
35
+ __all__ = [
36
+ 'read',
37
+ 'write',
38
+ ]
39
+
40
+
41
+ # SECTION: INTERNAL CONSTANTS =============================================== #
42
+
43
+
44
+ _PRIMITIVE_TYPES: tuple[type, ...] = (
45
+ bool,
46
+ int,
47
+ float,
48
+ str,
49
+ bytes,
50
+ bytearray,
51
+ )
52
+
53
+
54
+ # SECTION: INTERNAL FUNCTIONS =============================================== #
55
+
56
+
57
+ def _infer_schema(records: JSONList) -> dict[str, Any]:
58
+ """
59
+ Infer a basic Avro schema from record payloads.
60
+
61
+ Only primitive field values are supported; complex values raise TypeError.
62
+ """
63
+ field_names = sorted({key for record in records for key in record})
64
+ fields: list[dict[str, Any]] = []
65
+ for name in field_names:
66
+ types: list[str] = []
67
+ for record in records:
68
+ value = record.get(name)
69
+ if value is None:
70
+ types.append('null')
71
+ continue
72
+ if isinstance(value, dict | list):
73
+ raise TypeError(
74
+ 'AVRO payloads must contain only primitive values',
75
+ )
76
+ if not isinstance(value, _PRIMITIVE_TYPES):
77
+ raise TypeError(
78
+ 'AVRO payloads must contain only primitive values',
79
+ )
80
+ types.append(cast(str, _infer_value_type(value)))
81
+ fields.append({'name': name, 'type': _merge_types(types)})
82
+
83
+ return {
84
+ 'name': 'etlplus_record',
85
+ 'type': 'record',
86
+ 'fields': fields,
87
+ }
88
+
89
+
90
+ def _infer_value_type(value: object) -> str | list[str]:
91
+ """
92
+ Infer the Avro type for a primitive value.
93
+
94
+ Raises TypeError for unsupported types.
95
+ """
96
+ if value is None:
97
+ return 'null'
98
+ if isinstance(value, bool):
99
+ return 'boolean'
100
+ if isinstance(value, int):
101
+ return 'long'
102
+ if isinstance(value, float):
103
+ return 'double'
104
+ if isinstance(value, str):
105
+ return 'string'
106
+ if isinstance(value, (bytes, bytearray)):
107
+ return 'bytes'
108
+ raise TypeError('AVRO payloads must contain only primitive values')
109
+
110
+
111
+ def _merge_types(types: list[str]) -> str | list[str]:
112
+ """Return a stable Avro type union for a list of types."""
113
+ unique = list(dict.fromkeys(types))
114
+ if len(unique) == 1:
115
+ return unique[0]
116
+ ordered = ['null'] + sorted(t for t in unique if t != 'null')
117
+ return ordered
118
+
119
+
120
+ # SECTION: FUNCTIONS ======================================================== #
121
+
122
+
123
+ def read(
124
+ path: Path,
125
+ ) -> JSONList:
126
+ """
127
+ Read AVRO content from ``path``.
128
+
129
+ Parameters
130
+ ----------
131
+ path : Path
132
+ Path to the AVRO file on disk.
133
+
134
+ Returns
135
+ -------
136
+ JSONList
137
+ The list of dictionaries read from the AVRO file.
138
+ """
139
+ fastavro = get_fastavro()
140
+ with path.open('rb') as handle:
141
+ reader = fastavro.reader(handle)
142
+ return [cast(JSONDict, record) for record in reader]
143
+
144
+
145
+ def write(
146
+ path: Path,
147
+ data: JSONData,
148
+ ) -> int:
149
+ """
150
+ Write ``data`` to AVRO at ``path`` and return record count.
151
+
152
+ Parameters
153
+ ----------
154
+ path : Path
155
+ Path to the AVRO file on disk.
156
+ data : JSONData
157
+ Data to write.
158
+
159
+ Returns
160
+ -------
161
+ int
162
+ Number of records written.
163
+ """
164
+ records = normalize_records(data, 'AVRO')
165
+ if not records:
166
+ return 0
167
+
168
+ fastavro = get_fastavro()
169
+ schema = _infer_schema(records)
170
+ parsed_schema = fastavro.parse_schema(schema)
171
+
172
+ path.parent.mkdir(parents=True, exist_ok=True)
173
+ with path.open('wb') as handle:
174
+ fastavro.writer(handle, parsed_schema, records)
175
+
176
+ return len(records)
etlplus/file/bson.py ADDED
@@ -0,0 +1,77 @@
1
+ """
2
+ :mod:`etlplus.file.bson` module.
3
+
4
+ Helpers for reading/writing Binary JSON (BSON) files.
5
+
6
+ Notes
7
+ -----
8
+ - A BSON file is a binary-encoded serialization of JSON-like documents.
9
+ - Common cases:
10
+ - Data storage in MongoDB.
11
+ - Efficient data interchange between systems.
12
+ - Handling of complex data types not supported in standard JSON.
13
+ - Rule of thumb:
14
+ - If the file follows the BSON specification, use this module for reading
15
+ and writing.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ from pathlib import Path
21
+
22
+ from ..types import JSONData
23
+ from ..types import JSONList
24
+ from . import stub
25
+
26
+ # SECTION: EXPORTS ========================================================== #
27
+
28
+
29
+ __all__ = [
30
+ 'read',
31
+ 'write',
32
+ ]
33
+
34
+
35
+ # SECTION: FUNCTIONS ======================================================== #
36
+
37
+
38
+ def read(
39
+ path: Path,
40
+ ) -> JSONList:
41
+ """
42
+ Read BSON content from ``path``.
43
+
44
+ Parameters
45
+ ----------
46
+ path : Path
47
+ Path to the BSON file on disk.
48
+
49
+ Returns
50
+ -------
51
+ JSONList
52
+ The list of dictionaries read from the BSON file.
53
+ """
54
+ return stub.read(path, format_name='BSON')
55
+
56
+
57
+ def write(
58
+ path: Path,
59
+ data: JSONData,
60
+ ) -> int:
61
+ """
62
+ Write ``data`` to BSON at ``path`` and return record count.
63
+
64
+ Parameters
65
+ ----------
66
+ path : Path
67
+ Path to the BSON file on disk.
68
+ data : JSONData
69
+ Data to write as BSON. Should be a list of dictionaries or a
70
+ single dictionary.
71
+
72
+ Returns
73
+ -------
74
+ int
75
+ The number of rows written to the BSON file.
76
+ """
77
+ return stub.write(path, data, format_name='BSON')
etlplus/file/cbor.py ADDED
@@ -0,0 +1,78 @@
1
+ """
2
+ :mod:`etlplus.file.cbor` module.
3
+
4
+ Helpers for reading/writing Concise Binary Object Representation (CBOR) files.
5
+
6
+ Notes
7
+ -----
8
+ - A CBOR file is a binary data format designed for small code size and message
9
+ size, suitable for constrained environments.
10
+ - Common cases:
11
+ - IoT data interchange.
12
+ - Efficient data serialization.
13
+ - Storage of structured data in a compact binary form.
14
+ - Rule of thumb:
15
+ - If the file follows the CBOR specification, use this module for reading
16
+ and writing.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ from pathlib import Path
22
+
23
+ from ..types import JSONData
24
+ from ..types import JSONList
25
+ from . import stub
26
+
27
+ # SECTION: EXPORTS ========================================================== #
28
+
29
+
30
+ __all__ = [
31
+ 'read',
32
+ 'write',
33
+ ]
34
+
35
+
36
+ # SECTION: FUNCTIONS ======================================================== #
37
+
38
+
39
+ def read(
40
+ path: Path,
41
+ ) -> JSONList:
42
+ """
43
+ Read CBOR content from ``path``.
44
+
45
+ Parameters
46
+ ----------
47
+ path : Path
48
+ Path to the CBOR file on disk.
49
+
50
+ Returns
51
+ -------
52
+ JSONList
53
+ The list of dictionaries read from the CBOR file.
54
+ """
55
+ return stub.read(path, format_name='CBOR')
56
+
57
+
58
+ def write(
59
+ path: Path,
60
+ data: JSONData,
61
+ ) -> int:
62
+ """
63
+ Write ``data`` to CBOR at ``path`` and return record count.
64
+
65
+ Parameters
66
+ ----------
67
+ path : Path
68
+ Path to the CBOR file on disk.
69
+ data : JSONData
70
+ Data to write as CBOR. Should be a list of dictionaries or a
71
+ single dictionary.
72
+
73
+ Returns
74
+ -------
75
+ int
76
+ The number of rows written to the CBOR file.
77
+ """
78
+ return stub.write(path, data, format_name='CBOR')
etlplus/file/cfg.py ADDED
@@ -0,0 +1,79 @@
1
+ """
2
+ :mod:`etlplus.file.cfg` module.
3
+
4
+ Helpers for reading/writing config (CFG) files.
5
+
6
+ Notes
7
+ -----
8
+ - A CFG file is a configuration file that may use various syntaxes, such as
9
+ INI, YAML, or custom formats.
10
+ - Common cases:
11
+ - INI-style key-value pairs with sections (such as in Python ecosystems,
12
+ using ``configparser``).
13
+ - YAML-like structures with indentation.
14
+ - Custom formats specific to certain applications.
15
+ - Rule of thumb:
16
+ - If the file follows a standard format like INI or YAML, consider using
17
+ dedicated parsers.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ from pathlib import Path
23
+
24
+ from ..types import JSONData
25
+ from ..types import JSONList
26
+ from . import stub
27
+
28
+ # SECTION: EXPORTS ========================================================== #
29
+
30
+
31
+ __all__ = [
32
+ 'read',
33
+ 'write',
34
+ ]
35
+
36
+
37
+ # SECTION: FUNCTIONS ======================================================== #
38
+
39
+
40
+ def read(
41
+ path: Path,
42
+ ) -> JSONList:
43
+ """
44
+ Read CFG content from ``path``.
45
+
46
+ Parameters
47
+ ----------
48
+ path : Path
49
+ Path to the CFG file on disk.
50
+
51
+ Returns
52
+ -------
53
+ JSONList
54
+ The list of dictionaries read from the CFG file.
55
+ """
56
+ return stub.read(path, format_name='CFG')
57
+
58
+
59
+ def write(
60
+ path: Path,
61
+ data: JSONData,
62
+ ) -> int:
63
+ """
64
+ Write ``data`` to CFG file at ``path`` and return record count.
65
+
66
+ Parameters
67
+ ----------
68
+ path : Path
69
+ Path to the CFG file on disk.
70
+ data : JSONData
71
+ Data to write as CFG file. Should be a list of dictionaries or a
72
+ single dictionary.
73
+
74
+ Returns
75
+ -------
76
+ int
77
+ The number of rows written to the CFG file.
78
+ """
79
+ return stub.write(path, data, format_name='CFG')
etlplus/file/conf.py ADDED
@@ -0,0 +1,80 @@
1
+ """
2
+ :mod:`etlplus.file.conf` module.
3
+
4
+ Helpers for reading/writing config (CONF) files.
5
+
6
+ Notes
7
+ -----
8
+ - A CONF file is a configuration file that may use various syntaxes, such as
9
+ INI, YAML, or custom formats.
10
+ - Common cases:
11
+ - INI-style key-value pairs with sections.
12
+ - YAML-like structures with indentation.
13
+ - Custom formats specific to certain applications (such as Unix-like
14
+ systems, where ``.conf`` is a strong convention for "This is a
15
+ configuration file").
16
+ - Rule of thumb:
17
+ - If the file follows a standard format like INI or YAML, consider using
18
+ dedicated parsers.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from pathlib import Path
24
+
25
+ from ..types import JSONData
26
+ from ..types import JSONList
27
+ from . import stub
28
+
29
+ # SECTION: EXPORTS ========================================================== #
30
+
31
+
32
+ __all__ = [
33
+ 'read',
34
+ 'write',
35
+ ]
36
+
37
+
38
+ # SECTION: FUNCTIONS ======================================================== #
39
+
40
+
41
+ def read(
42
+ path: Path,
43
+ ) -> JSONList:
44
+ """
45
+ Read CONF content from ``path``.
46
+
47
+ Parameters
48
+ ----------
49
+ path : Path
50
+ Path to the CONF file on disk.
51
+
52
+ Returns
53
+ -------
54
+ JSONList
55
+ The list of dictionaries read from the CONF file.
56
+ """
57
+ return stub.read(path, format_name='CONF')
58
+
59
+
60
+ def write(
61
+ path: Path,
62
+ data: JSONData,
63
+ ) -> int:
64
+ """
65
+ Write ``data`` to CONF at ``path`` and return record count.
66
+
67
+ Parameters
68
+ ----------
69
+ path : Path
70
+ Path to the CONF file on disk.
71
+ data : JSONData
72
+ Data to write as CONF. Should be a list of dictionaries or a
73
+ single dictionary.
74
+
75
+ Returns
76
+ -------
77
+ int
78
+ The number of rows written to the CONF file.
79
+ """
80
+ return stub.write(path, data, format_name='CONF')