etlplus 0.4.1__py3-none-any.whl → 0.4.5__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/cli/main.py CHANGED
@@ -22,7 +22,6 @@ from ..enums import FileFormat
22
22
  from ..utils import json_type
23
23
  from .app import PROJECT_URL
24
24
  from .app import app
25
- from .handlers import FORMAT_ENV_KEY
26
25
  from .handlers import cmd_extract
27
26
  from .handlers import cmd_list
28
27
  from .handlers import cmd_load
@@ -51,7 +50,9 @@ type FormatContext = Literal['source', 'target']
51
50
 
52
51
 
53
52
  class _FormatAction(argparse.Action):
54
- """Argparse action that records when ``--format`` is provided."""
53
+ """
54
+ Argparse action that records when ``--source-format`` or
55
+ ``--target-format`` is provided."""
55
56
 
56
57
  def __call__(
57
58
  self,
@@ -67,35 +68,93 @@ class _FormatAction(argparse.Action):
67
68
  # SECTION: INTERNAL FUNCTIONS =============================================== #
68
69
 
69
70
 
71
+ def _add_config_option(
72
+ parser: argparse.ArgumentParser,
73
+ *,
74
+ required: bool = True,
75
+ ) -> None:
76
+ """Attach the shared ``--config`` option used by legacy commands.
77
+
78
+ Parameters
79
+ ----------
80
+ parser : argparse.ArgumentParser
81
+ Parser receiving the option.
82
+ required : bool, optional
83
+ Whether the flag must be provided. Defaults to ``True``.
84
+ """
85
+
86
+ parser.add_argument(
87
+ '--config',
88
+ required=required,
89
+ help='Path to pipeline YAML configuration file',
90
+ )
91
+
92
+
70
93
  def _add_format_options(
71
94
  parser: argparse.ArgumentParser,
72
95
  *,
73
96
  context: FormatContext,
74
97
  ) -> None:
75
- """Attach shared ``--format`` options to extract/load parsers."""
98
+ """
99
+ Attach shared ``--source-format`` or ``--target-format`` options to
100
+ extract/load parsers.
76
101
 
102
+ Parameters
103
+ ----------
104
+ parser : argparse.ArgumentParser
105
+ Parser to augment.
106
+ context : FormatContext
107
+ Context for the format option: either ``'source'`` or ``'target'``
108
+ """
77
109
  parser.set_defaults(_format_explicit=False)
78
110
  parser.add_argument(
79
- '--strict-format',
80
- action='store_true',
111
+ '--source-format',
112
+ choices=list(FileFormat.choices()),
113
+ default='json',
114
+ action=_FormatAction,
81
115
  help=(
82
- 'Treat providing --format for file '
83
- f'{context}s as an error (overrides environment behavior)'
116
+ f'Format of the {context}. Overrides filename-based inference '
117
+ 'when provided.'
84
118
  ),
85
119
  )
86
120
  parser.add_argument(
87
- '--format',
121
+ '--target-format',
88
122
  choices=list(FileFormat.choices()),
89
123
  default='json',
90
124
  action=_FormatAction,
91
125
  help=(
92
- f'Format of the {context} when not a file. For file {context}s '
93
- 'this option is ignored and the format is inferred from the '
94
- 'filename extension.'
126
+ f'Format of the {context}. Overrides filename-based inference '
127
+ 'when provided.'
95
128
  ),
96
129
  )
97
130
 
98
131
 
132
+ def _add_boolean_flag(
133
+ parser: argparse.ArgumentParser,
134
+ *,
135
+ name: str,
136
+ help_text: str,
137
+ ) -> None:
138
+ """Add a toggle that also supports the ``--no-`` prefix via 3.13.
139
+
140
+ Parameters
141
+ ----------
142
+ parser : argparse.ArgumentParser
143
+ Parser receiving the flag.
144
+ name : str
145
+ Primary flag name without leading dashes.
146
+ help_text : str
147
+ Help text rendered in ``--help`` output.
148
+ """
149
+
150
+ parser.add_argument(
151
+ f'--{name}',
152
+ action=argparse.BooleanOptionalAction,
153
+ default=False,
154
+ help=help_text,
155
+ )
156
+
157
+
99
158
  def _cli_description() -> str:
100
159
  return '\n'.join(
101
160
  [
@@ -103,40 +162,28 @@ def _cli_description() -> str:
103
162
  '',
104
163
  ' Provide a subcommand and options. Examples:',
105
164
  '',
106
- ' etlplus extract file in.csv -o out.json',
165
+ ' etlplus extract file in.csv > out.json',
107
166
  ' etlplus validate in.json --rules \'{"required": ["id"]}\'',
108
167
  (
109
- ' etlplus transform in.json --operations '
110
- '\'{"select": ["id"]}\''
168
+ ' etlplus transform --from file in.csv --operations '
169
+ '\'{"select": ["id"]}\' --to file -o out.json'
111
170
  ),
112
- ' etlplus load in.json file out.json',
171
+ ' etlplus extract in.csv | etlplus load --to file out.json',
113
172
  '',
114
- ' Enforce error if --format is provided for files. Examples:',
173
+ ' Override format inference when extensions are misleading:',
115
174
  '',
116
- ' etlplus extract file in.csv --format csv --strict-format',
117
- (
118
- ' etlplus load in.json file out.csv --format csv '
119
- '--strict-format'
120
- ),
175
+ ' etlplus extract data.txt --source-format csv',
176
+ ' etlplus load payload.bin --target-format json',
121
177
  ],
122
178
  )
123
179
 
124
180
 
125
- def _cli_epilog(format_env_key: str) -> str:
181
+ def _cli_epilog() -> str:
126
182
  return '\n'.join(
127
183
  [
128
- 'Environment:',
129
- (
130
- f' {format_env_key} controls behavior when '
131
- '--format is provided for files.'
132
- ),
133
- ' Values:',
134
- ' - error|fail|strict: treat as error',
135
- ' - warn (default): print a warning',
136
- ' - ignore|silent: no message',
137
- '',
138
- 'Note:',
139
- ' --strict-format overrides the environment behavior.',
184
+ 'Tip:',
185
+ ' --source-format and --target-format override format '
186
+ 'inference based on filename extensions when needed.',
140
187
  ],
141
188
  )
142
189
 
@@ -157,7 +204,7 @@ def create_parser() -> argparse.ArgumentParser:
157
204
  parser = argparse.ArgumentParser(
158
205
  prog='etlplus',
159
206
  description=_cli_description(),
160
- epilog=_cli_epilog(FORMAT_ENV_KEY),
207
+ epilog=_cli_epilog(),
161
208
  formatter_class=argparse.RawDescriptionHelpFormatter,
162
209
  )
163
210
 
@@ -172,6 +219,7 @@ def create_parser() -> argparse.ArgumentParser:
172
219
  dest='command',
173
220
  help='Available commands',
174
221
  )
222
+ subparsers.required = True
175
223
 
176
224
  extract_parser = subparsers.add_parser(
177
225
  'extract',
@@ -190,11 +238,6 @@ def create_parser() -> argparse.ArgumentParser:
190
238
  'or API URL)'
191
239
  ),
192
240
  )
193
- extract_parser.add_argument(
194
- '-o',
195
- '--output',
196
- help='Output file to save extracted data (JSON format)',
197
- )
198
241
  _add_format_options(extract_parser, context='source')
199
242
  extract_parser.set_defaults(func=cmd_extract)
200
243
 
@@ -231,9 +274,35 @@ def create_parser() -> argparse.ArgumentParser:
231
274
  help='Transformation operations as JSON string',
232
275
  )
233
276
  transform_parser.add_argument(
234
- '-o',
235
- '--output',
236
- help='Output file to save transformed data',
277
+ '--from',
278
+ dest='from_',
279
+ choices=list(DataConnectorType.choices()),
280
+ help='Override the inferred source type (file, database, api).',
281
+ )
282
+ transform_parser.add_argument(
283
+ '--to',
284
+ dest='to',
285
+ choices=list(DataConnectorType.choices()),
286
+ help='Override the inferred target type (file, database, api).',
287
+ )
288
+ transform_parser.add_argument(
289
+ '--source-format',
290
+ choices=list(FileFormat.choices()),
291
+ dest='source_format',
292
+ help=(
293
+ 'Input payload format when SOURCE is - or a literal payload. '
294
+ 'File sources infer format from the extension.'
295
+ ),
296
+ )
297
+ transform_parser.add_argument(
298
+ '--target-format',
299
+ dest='target_format',
300
+ choices=list(FileFormat.choices()),
301
+ help=(
302
+ 'Output payload format '
303
+ 'when writing to stdout or non-file targets. '
304
+ 'File targets infer format from the extension.'
305
+ ),
237
306
  )
238
307
  transform_parser.set_defaults(func=cmd_transform)
239
308
 
@@ -269,11 +338,7 @@ def create_parser() -> argparse.ArgumentParser:
269
338
  ),
270
339
  formatter_class=argparse.ArgumentDefaultsHelpFormatter,
271
340
  )
272
- pipe_parser.add_argument(
273
- '--config',
274
- required=True,
275
- help='Path to pipeline YAML configuration file',
276
- )
341
+ _add_config_option(pipe_parser)
277
342
  pipe_parser.add_argument(
278
343
  '--list',
279
344
  action='store_true',
@@ -291,30 +356,26 @@ def create_parser() -> argparse.ArgumentParser:
291
356
  help='List ETL pipeline metadata',
292
357
  formatter_class=argparse.ArgumentDefaultsHelpFormatter,
293
358
  )
294
- list_parser.add_argument(
295
- '--config',
296
- required=True,
297
- help='Path to pipeline YAML configuration file',
359
+ _add_config_option(list_parser)
360
+ _add_boolean_flag(
361
+ list_parser,
362
+ name='pipelines',
363
+ help_text='List ETL pipelines',
298
364
  )
299
- list_parser.add_argument(
300
- '--pipelines',
301
- action='store_true',
302
- help='List ETL pipelines',
365
+ _add_boolean_flag(
366
+ list_parser,
367
+ name='sources',
368
+ help_text='List data sources',
303
369
  )
304
- list_parser.add_argument(
305
- '--sources',
306
- action='store_true',
307
- help='List data sources',
308
- )
309
- list_parser.add_argument(
310
- '--targets',
311
- action='store_true',
312
- help='List data targets',
370
+ _add_boolean_flag(
371
+ list_parser,
372
+ name='targets',
373
+ help_text='List data targets',
313
374
  )
314
- list_parser.add_argument(
315
- '--transforms',
316
- action='store_true',
317
- help='List data transforms',
375
+ _add_boolean_flag(
376
+ list_parser,
377
+ name='transforms',
378
+ help_text='List data transforms',
318
379
  )
319
380
  list_parser.set_defaults(func=cmd_list)
320
381
 
@@ -326,11 +387,7 @@ def create_parser() -> argparse.ArgumentParser:
326
387
  ),
327
388
  formatter_class=argparse.ArgumentDefaultsHelpFormatter,
328
389
  )
329
- run_parser.add_argument(
330
- '--config',
331
- required=True,
332
- help='Path to pipeline YAML configuration file',
333
- )
390
+ _add_config_option(run_parser)
334
391
  run_parser.add_argument(
335
392
  '-j',
336
393
  '--job',
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: etlplus
3
- Version: 0.4.1
3
+ Version: 0.4.5
4
4
  Summary: A Swiss Army knife for simple ETL operations
5
5
  Home-page: https://github.com/Dagitali/ETLPlus
6
6
  Author: ETLPlus Team
@@ -67,7 +67,7 @@ package and command-line interface for data extraction, validation, transformati
67
67
  - [Load Data](#load-data)
68
68
  - [Python API](#python-api)
69
69
  - [Complete ETL Pipeline Example](#complete-etl-pipeline-example)
70
- - [Environment Variables](#environment-variables)
70
+ - [Format Overrides](#format-overrides)
71
71
  - [Transformation Operations](#transformation-operations)
72
72
  - [Filter Operations](#filter-operations)
73
73
  - [Aggregation Functions](#aggregation-functions)
@@ -79,6 +79,8 @@ package and command-line interface for data extraction, validation, transformati
79
79
  - [Test Layers](#test-layers)
80
80
  - [Code Coverage](#code-coverage)
81
81
  - [Linting](#linting)
82
+ - [Updating Demo Snippets](#updating-demo-snippets)
83
+ - [Releasing to PyPI](#releasing-to-pypi)
82
84
  - [Links](#links)
83
85
  - [License](#license)
84
86
  - [Contributing](#contributing)
@@ -169,9 +171,9 @@ etlplus --version
169
171
 
170
172
  #### Extract Data
171
173
 
172
- Note: For file sources, the format is inferred from the filename extension; the `--format` option is
173
- ignored. To treat passing `--format` as an error for file sources, either set
174
- `ETLPLUS_FORMAT_BEHAVIOR=error` or pass the CLI flag `--strict-format`.
174
+ Note: For file sources, the format is normally inferred from the filename extension. Use
175
+ `--source-format` to override inference when a file lacks an extension or when you want to force a
176
+ specific parser.
175
177
 
176
178
  Extract from JSON file:
177
179
  ```bash
@@ -212,6 +214,20 @@ etlplus validate examples/data/sample.json --rules '{"email": {"type": "string",
212
214
 
213
215
  #### Transform Data
214
216
 
217
+ When piping data through `etlplus transform`, use `--source-format` whenever the SOURCE argument is
218
+ `-` or a literal payload, mirroring the `etlplus extract` semantics. Use `--target-format` to
219
+ control the emitted format for stdout or other non-file outputs, just like `etlplus load`. File
220
+ paths continue to infer formats from their extensions. Use `--from` to override the inferred source
221
+ connector type and `--to` to override the inferred target connector type, matching the `etlplus
222
+ extract`/`etlplus load` behavior.
223
+
224
+ Transform file inputs while overriding connector types:
225
+ ```bash
226
+ etlplus transform --from file examples/data/sample.json \
227
+ --operations '{"select": ["name", "email"]}' \
228
+ --to file -o temp/selected_output.json
229
+ ```
230
+
215
231
  Filter and select fields:
216
232
  ```bash
217
233
  etlplus transform '[{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]' \
@@ -235,19 +251,24 @@ etlplus transform examples/data/sample.json --operations '{"map": {"name": "new_
235
251
 
236
252
  #### Load Data
237
253
 
254
+ `etlplus load` consumes JSON from stdin; provide only the target argument plus optional flags.
255
+
238
256
  Load to JSON file:
239
257
  ```bash
240
- etlplus load '{"name": "John", "age": 30}' file temp/sample_output.json
258
+ etlplus extract file examples/data/sample.json \
259
+ | etlplus load --to file temp/sample_output.json
241
260
  ```
242
261
 
243
262
  Load to CSV file:
244
263
  ```bash
245
- etlplus load '[{"name": "John", "age": 30}]' file temp/sample_output.csv
264
+ etlplus extract file examples/data/sample.csv \
265
+ | etlplus load --to file temp/sample_output.csv
246
266
  ```
247
267
 
248
268
  Load to REST API:
249
269
  ```bash
250
- etlplus load examples/data/sample.json api https://api.example.com/endpoint
270
+ cat examples/data/sample.json \
271
+ | etlplus load --to api https://api.example.com/endpoint
251
272
  ```
252
273
 
253
274
  ### Python API
@@ -301,41 +322,28 @@ etlplus validate temp/sample_transformed.json \
301
322
  --rules '{"name": {"type": "string", "required": true}, "email": {"type": "string", "required": true}}'
302
323
 
303
324
  # 4. Load to CSV
304
- etlplus load temp/sample_transformed.json file temp/sample_output.csv
325
+ cat temp/sample_transformed.json \
326
+ | etlplus load --to temp/sample_output.csv
305
327
  ```
306
328
 
307
- ### Environment Variables
308
-
309
- ETLPlus honors a small number of environment toggles to refine CLI behavior:
329
+ ### Format Overrides
310
330
 
311
- - `ETLPLUS_FORMAT_BEHAVIOR`: controls what happens when `--format` is provided for
312
- file sources or targets (extract/load) where the format is inferred from the
313
- filename extension.
314
- - `error|fail|strict`: treat as error (non-zero exit)
315
- - `warn` (default): print a warning to stderr
316
- - `ignore|silent`: no message
317
- - Precedence: the CLI flag `--strict-format` overrides the environment.
331
+ `--source-format` and `--target-format` override whichever format would normally be inferred from a
332
+ file extension. This is useful when an input lacks an extension (for example, `records.txt` that
333
+ actually contains CSV) or when you intentionally want to treat a file as another format.
318
334
 
319
335
  Examples (zsh):
320
336
 
321
337
  ```zsh
322
- # Warn (default)
323
- etlplus extract file data.csv --format csv
324
- etlplus load data.json file out.csv --format csv
325
-
326
- # Enforce error via environment
327
- ETLPLUS_FORMAT_BEHAVIOR=error \
328
- etlplus extract file data.csv --format csv
329
- ETLPLUS_FORMAT_BEHAVIOR=error \
330
- etlplus load data.json file out.csv --format csv
331
-
332
- # Equivalent strict behavior via flag (overrides environment)
333
- etlplus extract file data.csv --format csv --strict-format
334
- etlplus load data.json file out.csv --format csv --strict-format
335
-
336
- # Recommended: rely on extension, no --format needed for files
337
- etlplus extract file data.csv
338
- etlplus load data.json file out.csv
338
+ # Force CSV parsing for an extension-less file
339
+ etlplus extract --from file data.txt --source-format csv
340
+
341
+ # Write CSV to a file without the .csv suffix
342
+ etlplus load --to file output.bin --target-format csv < data.json
343
+
344
+ # Leave the flags off when extensions already match the desired format
345
+ etlplus extract --from file data.csv
346
+ etlplus load --to file data.json < data.json
339
347
  ```
340
348
 
341
349
  ## Transformation Operations
@@ -31,9 +31,9 @@ etlplus/api/rate_limiting/__init__.py,sha256=ZySB1dZettEDnWvI1EHf_TZ9L08M_kKsNR-
31
31
  etlplus/api/rate_limiting/config.py,sha256=2b4wIynblN-1EyMqI4aXa71SljzSjXYh5N1Nngr3jOg,9406
32
32
  etlplus/api/rate_limiting/rate_limiter.py,sha256=Uxozqd_Ej5Lsj-M-mLT2WexChgWh7x35_YP10yqYPQA,7159
33
33
  etlplus/cli/__init__.py,sha256=J97-Rv931IL1_b4AXnB7Fbbd7HKnHBpx18NQfC_kE6c,299
34
- etlplus/cli/app.py,sha256=xNsre2GDErbQv3Cwd3hwRHpkkoh-ZYIbBLrnKrFs0VI,25268
35
- etlplus/cli/handlers.py,sha256=QlZTTg9R493J2R4z81yRS1Zt3XEGeiqmszGT_GT2c5A,16059
36
- etlplus/cli/main.py,sha256=nofNgGqfStGdyNLV6O8k8XguRNhMIm92EhuO68nGPOE,11148
34
+ etlplus/cli/app.py,sha256=pc9VDUb3Qc8u5-XyDrHJkrSR9D3bq4e9zLbaD8KzyfY,32618
35
+ etlplus/cli/handlers.py,sha256=aI_ZlnJCGGkVnVJJPhmPRCXc31MxtLaOeqqJoo3ci48,15816
36
+ etlplus/cli/main.py,sha256=9hoitdc9FisrXzwZniTglPWwKsODFAW-A-2QQV4NkBs,12565
37
37
  etlplus/config/__init__.py,sha256=VZWzOg7d2YR9NT6UwKTv44yf2FRUMjTHynkm1Dl5Qzo,1486
38
38
  etlplus/config/connector.py,sha256=0-TIwevHbKRHVmucvyGpPd-3tB1dKHB-dj0yJ6kq5eY,9809
39
39
  etlplus/config/jobs.py,sha256=hmzRCqt0OvCEZZR4ONKrd3lvSv0OmayjLc4yOBk3ug8,7399
@@ -43,9 +43,9 @@ etlplus/config/types.py,sha256=a0epJ3z16HQ5bY3Ctf8s_cQPa3f0HHcwdOcjCP2xoG4,4954
43
43
  etlplus/config/utils.py,sha256=4SUHMkt5bKBhMhiJm-DrnmE2Q4TfOgdNCKz8PJDS27o,3443
44
44
  etlplus/validation/__init__.py,sha256=Pe5Xg1_EA4uiNZGYu5WTF3j7odjmyxnAJ8rcioaplSQ,1254
45
45
  etlplus/validation/utils.py,sha256=Mtqg449VIke0ziy_wd2r6yrwJzQkA1iulZC87FzXMjo,10201
46
- etlplus-0.4.1.dist-info/licenses/LICENSE,sha256=MuNO63i6kWmgnV2pbP2SLqP54mk1BGmu7CmbtxMmT-U,1069
47
- etlplus-0.4.1.dist-info/METADATA,sha256=PGl9CCUvlxyqz_zNfG_ibDQ5iOxib70Vas1xeWURgA4,16758
48
- etlplus-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
- etlplus-0.4.1.dist-info/entry_points.txt,sha256=6w-2-jzuPa55spzK34h-UKh2JTEShh38adFRONNP9QE,45
50
- etlplus-0.4.1.dist-info/top_level.txt,sha256=aWWF-udn_sLGuHTM6W6MLh99ArS9ROkUWO8Mi8y1_2U,8
51
- etlplus-0.4.1.dist-info/RECORD,,
46
+ etlplus-0.4.5.dist-info/licenses/LICENSE,sha256=MuNO63i6kWmgnV2pbP2SLqP54mk1BGmu7CmbtxMmT-U,1069
47
+ etlplus-0.4.5.dist-info/METADATA,sha256=PVWEmnsziQdr2M-25xGsWlFQ3aCUj0VsNjgIQYktBg8,17278
48
+ etlplus-0.4.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
+ etlplus-0.4.5.dist-info/entry_points.txt,sha256=6w-2-jzuPa55spzK34h-UKh2JTEShh38adFRONNP9QE,45
50
+ etlplus-0.4.5.dist-info/top_level.txt,sha256=aWWF-udn_sLGuHTM6W6MLh99ArS9ROkUWO8Mi8y1_2U,8
51
+ etlplus-0.4.5.dist-info/RECORD,,