etlplus 0.12.3__tar.gz → 0.12.9__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.
- {etlplus-0.12.3/etlplus.egg-info → etlplus-0.12.9}/PKG-INFO +89 -1
- {etlplus-0.12.3 → etlplus-0.12.9}/README.md +88 -0
- etlplus-0.12.9/etlplus/file/_imports.py +141 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/_io.py +1 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/avro.py +4 -26
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/core.py +119 -84
- etlplus-0.12.9/etlplus/file/dat.py +66 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/enums.py +114 -15
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/feather.py +1 -1
- etlplus-0.12.9/etlplus/file/fwf.py +66 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/ndjson.py +2 -9
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/orc.py +1 -1
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/parquet.py +1 -1
- etlplus-0.12.9/etlplus/file/psv.py +66 -0
- etlplus-0.12.9/etlplus/file/stub.py +84 -0
- etlplus-0.12.9/etlplus/file/tab.py +82 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/txt.py +2 -9
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/xls.py +1 -1
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/xlsx.py +1 -1
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/yaml.py +3 -43
- {etlplus-0.12.3 → etlplus-0.12.9/etlplus.egg-info}/PKG-INFO +89 -1
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus.egg-info/SOURCES.txt +6 -1
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/database/test_u_database_ddl.py +3 -2
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/file/test_u_file_core.py +94 -76
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/file/test_u_file_enums.py +28 -19
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/file/test_u_file_yaml.py +8 -9
- etlplus-0.12.3/etlplus/file/_pandas.py +0 -58
- {etlplus-0.12.3 → etlplus-0.12.9}/.coveragerc +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/.editorconfig +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/.gitattributes +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/.github/actions/python-bootstrap/action.yml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/.github/workflows/ci.yml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/.gitignore +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/.pre-commit-config.yaml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/.ruff.toml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/CODE_OF_CONDUCT.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/CONTRIBUTING.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/DEMO.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/LICENSE +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/MANIFEST.in +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/Makefile +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/REFERENCES.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/SECURITY.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/SUPPORT.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/docs/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/docs/pipeline-guide.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/docs/snippets/installation_version.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/__main__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/__version__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/auth.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/config.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/endpoint_client.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/errors.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/pagination/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/pagination/client.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/pagination/config.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/pagination/paginator.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/rate_limiting/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/rate_limiting/config.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/rate_limiting/rate_limiter.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/request_manager.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/retry_manager.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/transport.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/api/types.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/commands.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/constants.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/handlers.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/io.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/main.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/options.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/state.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/cli/types.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/connector.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/jobs.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/pipeline.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/profile.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/types.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/config/utils.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/database/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/database/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/database/ddl.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/database/engine.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/database/orm.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/database/schema.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/database/types.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/enums.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/extract.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/csv.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/gz.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/json.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/tsv.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/xml.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/file/zip.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/load.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/mixins.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/py.typed +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/run.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/run_helpers.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/templates/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/templates/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/templates/ddl.sql.j2 +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/templates/view.sql.j2 +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/transform.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/types.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/utils.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/validate.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/validation/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/validation/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus/validation/utils.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus.egg-info/dependency_links.txt +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus.egg-info/entry_points.txt +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus.egg-info/requires.txt +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/etlplus.egg-info/top_level.txt +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/README.md +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/configs/ddl_spec.yml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/configs/pipeline.yml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/data/sample.csv +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/data/sample.json +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/data/sample.xml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/data/sample.xsd +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/data/sample.yaml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/examples/quickstart_python.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/pyproject.toml +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/pytest.ini +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/setup.cfg +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/setup.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/__init__.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/conftest.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/conftest.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_cli.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_examples_data_parity.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_pagination_strategy.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_pipeline_smoke.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_pipeline_yaml_load.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_run.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_run_profile_pagination_defaults.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/integration/test_i_run_profile_rate_limit_defaults.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/conftest.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_auth.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_config.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_endpoint_client.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_mocks.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_pagination_client.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_pagination_config.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_paginator.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_rate_limit_config.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_rate_limiter.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_request_manager.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_retry_manager.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_transport.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/api/test_u_types.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/cli/conftest.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/cli/test_u_cli_handlers.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/cli/test_u_cli_io.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/cli/test_u_cli_main.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/cli/test_u_cli_state.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/config/test_u_config_utils.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/config/test_u_connector.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/config/test_u_jobs.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/config/test_u_pipeline.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/conftest.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/database/test_u_database_engine.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/database/test_u_database_orm.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/database/test_u_database_schema.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_enums.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_extract.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_load.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_main.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_mixins.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_run.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_run_helpers.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_transform.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_utils.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_validate.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/test_u_version.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tests/unit/validation/test_u_validation_utils.py +0 -0
- {etlplus-0.12.3 → etlplus-0.12.9}/tools/update_demo_snippets.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: etlplus
|
|
3
|
-
Version: 0.12.
|
|
3
|
+
Version: 0.12.9
|
|
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
|
|
@@ -68,6 +68,17 @@ package and command-line interface for data extraction, validation, transformati
|
|
|
68
68
|
- [Features](#features)
|
|
69
69
|
- [Installation](#installation)
|
|
70
70
|
- [Quickstart](#quickstart)
|
|
71
|
+
- [Data Connectors](#data-connectors)
|
|
72
|
+
- [REST APIs (`api`)](#rest-apis-api)
|
|
73
|
+
- [Databases (`database`)](#databases-database)
|
|
74
|
+
- [Files (`file`)](#files-file)
|
|
75
|
+
- [Stubbed / Placeholder](#stubbed--placeholder)
|
|
76
|
+
- [Tabular \& Delimited Text](#tabular--delimited-text)
|
|
77
|
+
- [Semi-Structured Text](#semi-structured-text)
|
|
78
|
+
- [Columnar / Analytics-Friendly](#columnar--analytics-friendly)
|
|
79
|
+
- [Binary Serialization and Interchange](#binary-serialization-and-interchange)
|
|
80
|
+
- [Spreadsheets](#spreadsheets)
|
|
81
|
+
- [Data Archives](#data-archives)
|
|
71
82
|
- [Usage](#usage)
|
|
72
83
|
- [Command Line Interface](#command-line-interface)
|
|
73
84
|
- [Argument Order and Required Options](#argument-order-and-required-options)
|
|
@@ -191,6 +202,83 @@ assert validate(filtered, rules)["valid"]
|
|
|
191
202
|
load(filtered, "file", "temp/sample_output.json", file_format="json")
|
|
192
203
|
```
|
|
193
204
|
|
|
205
|
+
## Data Connectors
|
|
206
|
+
|
|
207
|
+
Data connectors abstract sources from which to extract data and targets to which to load data. They
|
|
208
|
+
are differentiated by their types, each of which is represented in the subsections below.
|
|
209
|
+
|
|
210
|
+
### REST APIs (`api`)
|
|
211
|
+
|
|
212
|
+
ETLPlus can extract from REST APIs and load results via common HTTP methods. Supported operations
|
|
213
|
+
include GET for extract and PATCH/POST/PUT for load.
|
|
214
|
+
|
|
215
|
+
### Databases (`database`)
|
|
216
|
+
|
|
217
|
+
Database connectors use connection strings for extraction and loading, and
|
|
218
|
+
DDL can be rendered from table specs for migrations or schema checks.
|
|
219
|
+
|
|
220
|
+
### Files (`file`)
|
|
221
|
+
|
|
222
|
+
File formats are grouped as in `FileFormat`. Support is marked as:
|
|
223
|
+
|
|
224
|
+
- **Y**: implemented (may require optional dependencies)
|
|
225
|
+
- **N**: stubbed or not yet implemented
|
|
226
|
+
|
|
227
|
+
#### Stubbed / Placeholder
|
|
228
|
+
|
|
229
|
+
| Format | Supported | Description |
|
|
230
|
+
| --- | --- | --- |
|
|
231
|
+
| `stub` | N | Placeholder format for tests and future connectors. |
|
|
232
|
+
|
|
233
|
+
#### Tabular & Delimited Text
|
|
234
|
+
|
|
235
|
+
| Format | Supported | Description |
|
|
236
|
+
| --- | --- | --- |
|
|
237
|
+
| `csv` | Y | Comma-Separated Values |
|
|
238
|
+
| `fwf` | N | Fixed-Width Fields |
|
|
239
|
+
| `dat` | N | Generic data file, often delimited or fixed-width |
|
|
240
|
+
| `psv` | N | Pipe-Separated Values |
|
|
241
|
+
| `tab` | N | Often synonymous with TSV |
|
|
242
|
+
| `tsv` | Y | Tab-Separated Values |
|
|
243
|
+
| `txt` | Y | Plain text, often delimited or fixed-width |
|
|
244
|
+
|
|
245
|
+
#### Semi-Structured Text
|
|
246
|
+
|
|
247
|
+
| Format | Supported | Description |
|
|
248
|
+
| --- | --- | --- |
|
|
249
|
+
| `json` | Y | JavaScript Object Notation |
|
|
250
|
+
| `ndjson` | Y | Newline-Delimited JSON |
|
|
251
|
+
| `xml` | Y | Extensible Markup Language |
|
|
252
|
+
| `yaml` | Y | YAML Ain't Markup Language |
|
|
253
|
+
|
|
254
|
+
#### Columnar / Analytics-Friendly
|
|
255
|
+
|
|
256
|
+
| Format | Supported | Description |
|
|
257
|
+
| --- | --- | --- |
|
|
258
|
+
| `feather` | Y | Apache Arrow Feather |
|
|
259
|
+
| `orc` | Y | Optimized Row Columnar; common in Hadoop |
|
|
260
|
+
| `parquet` | Y | Apache Parquet; common in Big Data |
|
|
261
|
+
|
|
262
|
+
#### Binary Serialization and Interchange
|
|
263
|
+
|
|
264
|
+
| Format | Supported | Description |
|
|
265
|
+
| --- | --- | --- |
|
|
266
|
+
| `avro` | Y | Apache Avro |
|
|
267
|
+
|
|
268
|
+
#### Spreadsheets
|
|
269
|
+
|
|
270
|
+
| Format | Supported | Description |
|
|
271
|
+
| --- | --- | --- |
|
|
272
|
+
| `xls` | Y | Microsoft Excel (BIFF); read-only |
|
|
273
|
+
| `xlsx` | Y | Microsoft Excel (Open XML) |
|
|
274
|
+
|
|
275
|
+
#### Data Archives
|
|
276
|
+
|
|
277
|
+
| Format | Supported | Description |
|
|
278
|
+
| --- | --- | --- |
|
|
279
|
+
| `gz` | Y | Gzip-compressed file |
|
|
280
|
+
| `zip` | Y | ZIP archive |
|
|
281
|
+
|
|
194
282
|
## Usage
|
|
195
283
|
|
|
196
284
|
### Command Line Interface
|
|
@@ -18,6 +18,17 @@ package and command-line interface for data extraction, validation, transformati
|
|
|
18
18
|
- [Features](#features)
|
|
19
19
|
- [Installation](#installation)
|
|
20
20
|
- [Quickstart](#quickstart)
|
|
21
|
+
- [Data Connectors](#data-connectors)
|
|
22
|
+
- [REST APIs (`api`)](#rest-apis-api)
|
|
23
|
+
- [Databases (`database`)](#databases-database)
|
|
24
|
+
- [Files (`file`)](#files-file)
|
|
25
|
+
- [Stubbed / Placeholder](#stubbed--placeholder)
|
|
26
|
+
- [Tabular \& Delimited Text](#tabular--delimited-text)
|
|
27
|
+
- [Semi-Structured Text](#semi-structured-text)
|
|
28
|
+
- [Columnar / Analytics-Friendly](#columnar--analytics-friendly)
|
|
29
|
+
- [Binary Serialization and Interchange](#binary-serialization-and-interchange)
|
|
30
|
+
- [Spreadsheets](#spreadsheets)
|
|
31
|
+
- [Data Archives](#data-archives)
|
|
21
32
|
- [Usage](#usage)
|
|
22
33
|
- [Command Line Interface](#command-line-interface)
|
|
23
34
|
- [Argument Order and Required Options](#argument-order-and-required-options)
|
|
@@ -141,6 +152,83 @@ assert validate(filtered, rules)["valid"]
|
|
|
141
152
|
load(filtered, "file", "temp/sample_output.json", file_format="json")
|
|
142
153
|
```
|
|
143
154
|
|
|
155
|
+
## Data Connectors
|
|
156
|
+
|
|
157
|
+
Data connectors abstract sources from which to extract data and targets to which to load data. They
|
|
158
|
+
are differentiated by their types, each of which is represented in the subsections below.
|
|
159
|
+
|
|
160
|
+
### REST APIs (`api`)
|
|
161
|
+
|
|
162
|
+
ETLPlus can extract from REST APIs and load results via common HTTP methods. Supported operations
|
|
163
|
+
include GET for extract and PATCH/POST/PUT for load.
|
|
164
|
+
|
|
165
|
+
### Databases (`database`)
|
|
166
|
+
|
|
167
|
+
Database connectors use connection strings for extraction and loading, and
|
|
168
|
+
DDL can be rendered from table specs for migrations or schema checks.
|
|
169
|
+
|
|
170
|
+
### Files (`file`)
|
|
171
|
+
|
|
172
|
+
File formats are grouped as in `FileFormat`. Support is marked as:
|
|
173
|
+
|
|
174
|
+
- **Y**: implemented (may require optional dependencies)
|
|
175
|
+
- **N**: stubbed or not yet implemented
|
|
176
|
+
|
|
177
|
+
#### Stubbed / Placeholder
|
|
178
|
+
|
|
179
|
+
| Format | Supported | Description |
|
|
180
|
+
| --- | --- | --- |
|
|
181
|
+
| `stub` | N | Placeholder format for tests and future connectors. |
|
|
182
|
+
|
|
183
|
+
#### Tabular & Delimited Text
|
|
184
|
+
|
|
185
|
+
| Format | Supported | Description |
|
|
186
|
+
| --- | --- | --- |
|
|
187
|
+
| `csv` | Y | Comma-Separated Values |
|
|
188
|
+
| `fwf` | N | Fixed-Width Fields |
|
|
189
|
+
| `dat` | N | Generic data file, often delimited or fixed-width |
|
|
190
|
+
| `psv` | N | Pipe-Separated Values |
|
|
191
|
+
| `tab` | N | Often synonymous with TSV |
|
|
192
|
+
| `tsv` | Y | Tab-Separated Values |
|
|
193
|
+
| `txt` | Y | Plain text, often delimited or fixed-width |
|
|
194
|
+
|
|
195
|
+
#### Semi-Structured Text
|
|
196
|
+
|
|
197
|
+
| Format | Supported | Description |
|
|
198
|
+
| --- | --- | --- |
|
|
199
|
+
| `json` | Y | JavaScript Object Notation |
|
|
200
|
+
| `ndjson` | Y | Newline-Delimited JSON |
|
|
201
|
+
| `xml` | Y | Extensible Markup Language |
|
|
202
|
+
| `yaml` | Y | YAML Ain't Markup Language |
|
|
203
|
+
|
|
204
|
+
#### Columnar / Analytics-Friendly
|
|
205
|
+
|
|
206
|
+
| Format | Supported | Description |
|
|
207
|
+
| --- | --- | --- |
|
|
208
|
+
| `feather` | Y | Apache Arrow Feather |
|
|
209
|
+
| `orc` | Y | Optimized Row Columnar; common in Hadoop |
|
|
210
|
+
| `parquet` | Y | Apache Parquet; common in Big Data |
|
|
211
|
+
|
|
212
|
+
#### Binary Serialization and Interchange
|
|
213
|
+
|
|
214
|
+
| Format | Supported | Description |
|
|
215
|
+
| --- | --- | --- |
|
|
216
|
+
| `avro` | Y | Apache Avro |
|
|
217
|
+
|
|
218
|
+
#### Spreadsheets
|
|
219
|
+
|
|
220
|
+
| Format | Supported | Description |
|
|
221
|
+
| --- | --- | --- |
|
|
222
|
+
| `xls` | Y | Microsoft Excel (BIFF); read-only |
|
|
223
|
+
| `xlsx` | Y | Microsoft Excel (Open XML) |
|
|
224
|
+
|
|
225
|
+
#### Data Archives
|
|
226
|
+
|
|
227
|
+
| Format | Supported | Description |
|
|
228
|
+
| --- | --- | --- |
|
|
229
|
+
| `gz` | Y | Gzip-compressed file |
|
|
230
|
+
| `zip` | Y | ZIP archive |
|
|
231
|
+
|
|
144
232
|
## Usage
|
|
145
233
|
|
|
146
234
|
### Command Line Interface
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""
|
|
2
|
+
:mod:`etlplus.file._imports` module.
|
|
3
|
+
|
|
4
|
+
Shared helpers for optional dependency imports.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from importlib import import_module
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
# SECTION: INTERNAL CONSTANTS =============================================== #
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
_MODULE_CACHE: dict[str, Any] = {}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# SECTION: INTERNAL FUNCTIONS =============================================== #
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _error_message(
|
|
22
|
+
module_name: str,
|
|
23
|
+
format_name: str,
|
|
24
|
+
) -> str:
|
|
25
|
+
"""
|
|
26
|
+
Build an import error message for an optional dependency.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
module_name : str
|
|
31
|
+
Module name to look up.
|
|
32
|
+
format_name : str
|
|
33
|
+
Human-readable format name for templated messages.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
str
|
|
38
|
+
Formatted error message.
|
|
39
|
+
"""
|
|
40
|
+
return (
|
|
41
|
+
f'{format_name} support requires '
|
|
42
|
+
f'optional dependency "{module_name}".\n'
|
|
43
|
+
f'Install with: pip install {module_name}'
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# SECTION: FUNCTIONS ======================================================== #
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_optional_module(
|
|
51
|
+
module_name: str,
|
|
52
|
+
*,
|
|
53
|
+
error_message: str,
|
|
54
|
+
) -> Any:
|
|
55
|
+
"""
|
|
56
|
+
Return an optional dependency module, caching on first import.
|
|
57
|
+
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
module_name : str
|
|
61
|
+
Name of the module to import.
|
|
62
|
+
error_message : str
|
|
63
|
+
Error message to surface when the module is missing.
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
Any
|
|
68
|
+
The imported module.
|
|
69
|
+
|
|
70
|
+
Raises
|
|
71
|
+
------
|
|
72
|
+
ImportError
|
|
73
|
+
If the optional dependency is missing.
|
|
74
|
+
"""
|
|
75
|
+
cached = _MODULE_CACHE.get(module_name)
|
|
76
|
+
if cached is not None: # pragma: no cover - tiny branch
|
|
77
|
+
return cached
|
|
78
|
+
try:
|
|
79
|
+
module = import_module(module_name)
|
|
80
|
+
except ImportError as e: # pragma: no cover
|
|
81
|
+
raise ImportError(error_message) from e
|
|
82
|
+
_MODULE_CACHE[module_name] = module
|
|
83
|
+
return module
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def get_fastavro() -> Any:
|
|
87
|
+
"""
|
|
88
|
+
Return the fastavro module, importing it on first use.
|
|
89
|
+
|
|
90
|
+
Raises an informative ImportError if the optional dependency is missing.
|
|
91
|
+
|
|
92
|
+
Notes
|
|
93
|
+
-----
|
|
94
|
+
Prefer :func:`get_optional_module` for new call sites.
|
|
95
|
+
"""
|
|
96
|
+
return get_optional_module(
|
|
97
|
+
'fastavro',
|
|
98
|
+
error_message=_error_message('fastavro', format_name='AVRO'),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def get_pandas(
|
|
103
|
+
format_name: str,
|
|
104
|
+
) -> Any:
|
|
105
|
+
"""
|
|
106
|
+
Return the pandas module, importing it on first use.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
format_name : str
|
|
111
|
+
Human-readable format name for error messages.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
Any
|
|
116
|
+
The pandas module.
|
|
117
|
+
|
|
118
|
+
Notes
|
|
119
|
+
-----
|
|
120
|
+
Prefer :func:`get_optional_module` for new call sites.
|
|
121
|
+
"""
|
|
122
|
+
return get_optional_module(
|
|
123
|
+
'pandas',
|
|
124
|
+
error_message=_error_message('pandas', format_name=format_name),
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def get_yaml() -> Any:
|
|
129
|
+
"""
|
|
130
|
+
Return the PyYAML module, importing it on first use.
|
|
131
|
+
|
|
132
|
+
Raises an informative ImportError if the optional dependency is missing.
|
|
133
|
+
|
|
134
|
+
Notes
|
|
135
|
+
-----
|
|
136
|
+
Prefer :func:`get_optional_module` for new call sites.
|
|
137
|
+
"""
|
|
138
|
+
return get_optional_module(
|
|
139
|
+
'yaml',
|
|
140
|
+
error_message=_error_message('PyYAML', format_name='YAML'),
|
|
141
|
+
)
|
|
@@ -107,6 +107,7 @@ def write_delimited(path: Path, data: JSONData, *, delimiter: str) -> int:
|
|
|
107
107
|
return 0
|
|
108
108
|
|
|
109
109
|
fieldnames = sorted({key for row in rows for key in row})
|
|
110
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
110
111
|
with path.open('w', encoding='utf-8', newline='') as handle:
|
|
111
112
|
writer = csv.DictWriter(
|
|
112
113
|
handle,
|
|
@@ -10,6 +10,8 @@ from pathlib import Path
|
|
|
10
10
|
from typing import Any
|
|
11
11
|
from typing import cast
|
|
12
12
|
|
|
13
|
+
from etlplus.file._imports import get_fastavro
|
|
14
|
+
|
|
13
15
|
from ..types import JSONData
|
|
14
16
|
from ..types import JSONDict
|
|
15
17
|
from ..types import JSONList
|
|
@@ -27,9 +29,6 @@ __all__ = [
|
|
|
27
29
|
# SECTION: INTERNAL CONSTANTS =============================================== #
|
|
28
30
|
|
|
29
31
|
|
|
30
|
-
_FASTAVRO_CACHE: dict[str, Any] = {}
|
|
31
|
-
|
|
32
|
-
|
|
33
32
|
_PRIMITIVE_TYPES: tuple[type, ...] = (
|
|
34
33
|
bool,
|
|
35
34
|
int,
|
|
@@ -43,27 +42,6 @@ _PRIMITIVE_TYPES: tuple[type, ...] = (
|
|
|
43
42
|
# SECTION: INTERNAL FUNCTIONS =============================================== #
|
|
44
43
|
|
|
45
44
|
|
|
46
|
-
def _get_fastavro() -> Any:
|
|
47
|
-
"""
|
|
48
|
-
Return the fastavro module, importing it on first use.
|
|
49
|
-
|
|
50
|
-
Raises an informative ImportError if the optional dependency is missing.
|
|
51
|
-
"""
|
|
52
|
-
mod = _FASTAVRO_CACHE.get('mod')
|
|
53
|
-
if mod is not None: # pragma: no cover - tiny branch
|
|
54
|
-
return mod
|
|
55
|
-
try:
|
|
56
|
-
_fastavro = __import__('fastavro') # type: ignore[assignment]
|
|
57
|
-
except ImportError as e: # pragma: no cover
|
|
58
|
-
raise ImportError(
|
|
59
|
-
'AVRO support requires optional dependency "fastavro".\n'
|
|
60
|
-
'Install with: pip install fastavro',
|
|
61
|
-
) from e
|
|
62
|
-
_FASTAVRO_CACHE['mod'] = _fastavro
|
|
63
|
-
|
|
64
|
-
return _fastavro
|
|
65
|
-
|
|
66
|
-
|
|
67
45
|
def _infer_schema(records: JSONList) -> dict[str, Any]:
|
|
68
46
|
"""
|
|
69
47
|
Infer a basic Avro schema from record payloads.
|
|
@@ -146,7 +124,7 @@ def read(
|
|
|
146
124
|
JSONList
|
|
147
125
|
The list of dictionaries read from the AVRO file.
|
|
148
126
|
"""
|
|
149
|
-
fastavro =
|
|
127
|
+
fastavro = get_fastavro()
|
|
150
128
|
with path.open('rb') as handle:
|
|
151
129
|
reader = fastavro.reader(handle)
|
|
152
130
|
return [cast(JSONDict, record) for record in reader]
|
|
@@ -175,7 +153,7 @@ def write(
|
|
|
175
153
|
if not records:
|
|
176
154
|
return 0
|
|
177
155
|
|
|
178
|
-
fastavro =
|
|
156
|
+
fastavro = get_fastavro()
|
|
179
157
|
schema = _infer_schema(records)
|
|
180
158
|
parsed_schema = fastavro.parse_schema(schema)
|
|
181
159
|
|
|
@@ -7,25 +7,15 @@ files.
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
import importlib
|
|
11
|
+
import inspect
|
|
10
12
|
from dataclasses import dataclass
|
|
13
|
+
from functools import cache
|
|
11
14
|
from pathlib import Path
|
|
15
|
+
from types import ModuleType
|
|
12
16
|
|
|
13
17
|
from ..types import JSONData
|
|
14
|
-
from . import avro
|
|
15
|
-
from . import csv
|
|
16
|
-
from . import feather
|
|
17
|
-
from . import gz
|
|
18
|
-
from . import json
|
|
19
|
-
from . import ndjson
|
|
20
|
-
from . import orc
|
|
21
|
-
from . import parquet
|
|
22
|
-
from . import tsv
|
|
23
|
-
from . import txt
|
|
24
|
-
from . import xls
|
|
25
|
-
from . import xlsx
|
|
26
18
|
from . import xml
|
|
27
|
-
from . import yaml
|
|
28
|
-
from . import zip as zip_
|
|
29
19
|
from .enums import FileFormat
|
|
30
20
|
from .enums import infer_file_format_and_compression
|
|
31
21
|
|
|
@@ -35,6 +25,53 @@ from .enums import infer_file_format_and_compression
|
|
|
35
25
|
__all__ = ['File']
|
|
36
26
|
|
|
37
27
|
|
|
28
|
+
# SECTION: INTERNAL FUNCTIONS =============================================== #
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _accepts_root_tag(handler: object) -> bool:
|
|
32
|
+
"""
|
|
33
|
+
Return True when ``handler`` supports a ``root_tag`` argument.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
handler : object
|
|
38
|
+
Callable to inspect.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
bool
|
|
43
|
+
True if ``root_tag`` is accepted by the handler.
|
|
44
|
+
"""
|
|
45
|
+
if not callable(handler):
|
|
46
|
+
return False
|
|
47
|
+
try:
|
|
48
|
+
signature = inspect.signature(handler)
|
|
49
|
+
except (TypeError, ValueError):
|
|
50
|
+
return False
|
|
51
|
+
for param in signature.parameters.values():
|
|
52
|
+
if param.kind is param.VAR_KEYWORD:
|
|
53
|
+
return True
|
|
54
|
+
return 'root_tag' in signature.parameters
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@cache
|
|
58
|
+
def _module_for_format(file_format: FileFormat) -> ModuleType:
|
|
59
|
+
"""
|
|
60
|
+
Import and return the module for ``file_format``.
|
|
61
|
+
|
|
62
|
+
Parameters
|
|
63
|
+
----------
|
|
64
|
+
file_format : FileFormat
|
|
65
|
+
File format enum value.
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
ModuleType
|
|
70
|
+
The module implementing IO for the format.
|
|
71
|
+
"""
|
|
72
|
+
return importlib.import_module(f'{__package__}.{file_format.value}')
|
|
73
|
+
|
|
74
|
+
|
|
38
75
|
# SECTION: CLASSES ========================================================== #
|
|
39
76
|
|
|
40
77
|
|
|
@@ -174,6 +211,53 @@ class File:
|
|
|
174
211
|
# Leave as None; _ensure_format() will raise on use if needed.
|
|
175
212
|
return None
|
|
176
213
|
|
|
214
|
+
def _resolve_handler(self, name: str) -> object:
|
|
215
|
+
"""
|
|
216
|
+
Resolve a handler from the module for the active file format.
|
|
217
|
+
|
|
218
|
+
Parameters
|
|
219
|
+
----------
|
|
220
|
+
name : str
|
|
221
|
+
Attribute name to resolve (``'read'`` or ``'write'``).
|
|
222
|
+
|
|
223
|
+
Returns
|
|
224
|
+
-------
|
|
225
|
+
object
|
|
226
|
+
Callable handler exported by the module.
|
|
227
|
+
|
|
228
|
+
Raises
|
|
229
|
+
------
|
|
230
|
+
ValueError
|
|
231
|
+
If the resolved file format is unsupported.
|
|
232
|
+
"""
|
|
233
|
+
module = self._resolve_module()
|
|
234
|
+
try:
|
|
235
|
+
return getattr(module, name)
|
|
236
|
+
except AttributeError as e:
|
|
237
|
+
raise ValueError(
|
|
238
|
+
f'Module {module.__name__} does not implement {name}()',
|
|
239
|
+
) from e
|
|
240
|
+
|
|
241
|
+
def _resolve_module(self) -> ModuleType:
|
|
242
|
+
"""
|
|
243
|
+
Resolve the IO module for the active file format.
|
|
244
|
+
|
|
245
|
+
Returns
|
|
246
|
+
-------
|
|
247
|
+
ModuleType
|
|
248
|
+
The module that implements read/write for the format.
|
|
249
|
+
|
|
250
|
+
Raises
|
|
251
|
+
------
|
|
252
|
+
ValueError
|
|
253
|
+
If the resolved file format is unsupported.
|
|
254
|
+
"""
|
|
255
|
+
fmt = self._ensure_format()
|
|
256
|
+
try:
|
|
257
|
+
return _module_for_format(fmt)
|
|
258
|
+
except ModuleNotFoundError as e:
|
|
259
|
+
raise ValueError(f'Unsupported format: {fmt}') from e
|
|
260
|
+
|
|
177
261
|
# -- Instance Methods -- #
|
|
178
262
|
|
|
179
263
|
def read(self) -> JSONData:
|
|
@@ -187,43 +271,18 @@ class File:
|
|
|
187
271
|
|
|
188
272
|
Raises
|
|
189
273
|
------
|
|
190
|
-
|
|
191
|
-
If the resolved
|
|
274
|
+
TypeError
|
|
275
|
+
If the resolved 'read' handler is not callable.
|
|
192
276
|
"""
|
|
193
277
|
self._assert_exists()
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
case FileFormat.GZ:
|
|
203
|
-
return gz.read(self.path)
|
|
204
|
-
case FileFormat.JSON:
|
|
205
|
-
return json.read(self.path)
|
|
206
|
-
case FileFormat.NDJSON:
|
|
207
|
-
return ndjson.read(self.path)
|
|
208
|
-
case FileFormat.ORC:
|
|
209
|
-
return orc.read(self.path)
|
|
210
|
-
case FileFormat.PARQUET:
|
|
211
|
-
return parquet.read(self.path)
|
|
212
|
-
case FileFormat.TSV:
|
|
213
|
-
return tsv.read(self.path)
|
|
214
|
-
case FileFormat.TXT:
|
|
215
|
-
return txt.read(self.path)
|
|
216
|
-
case FileFormat.XLS:
|
|
217
|
-
return xls.read(self.path)
|
|
218
|
-
case FileFormat.XLSX:
|
|
219
|
-
return xlsx.read(self.path)
|
|
220
|
-
case FileFormat.XML:
|
|
221
|
-
return xml.read(self.path)
|
|
222
|
-
case FileFormat.YAML:
|
|
223
|
-
return yaml.read(self.path)
|
|
224
|
-
case FileFormat.ZIP:
|
|
225
|
-
return zip_.read(self.path)
|
|
226
|
-
raise ValueError(f'Unsupported format: {fmt}')
|
|
278
|
+
reader = self._resolve_handler('read')
|
|
279
|
+
if callable(reader):
|
|
280
|
+
return reader(self.path)
|
|
281
|
+
else:
|
|
282
|
+
raise TypeError(
|
|
283
|
+
f"'read' handler for format {self.file_format} "
|
|
284
|
+
'is not callable',
|
|
285
|
+
)
|
|
227
286
|
|
|
228
287
|
def write(
|
|
229
288
|
self,
|
|
@@ -249,39 +308,15 @@ class File:
|
|
|
249
308
|
|
|
250
309
|
Raises
|
|
251
310
|
------
|
|
252
|
-
|
|
253
|
-
If the resolved
|
|
311
|
+
TypeError
|
|
312
|
+
If the resolved 'write' handler is not callable.
|
|
254
313
|
"""
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return gz.write(self.path, data)
|
|
265
|
-
case FileFormat.JSON:
|
|
266
|
-
return json.write(self.path, data)
|
|
267
|
-
case FileFormat.NDJSON:
|
|
268
|
-
return ndjson.write(self.path, data)
|
|
269
|
-
case FileFormat.ORC:
|
|
270
|
-
return orc.write(self.path, data)
|
|
271
|
-
case FileFormat.PARQUET:
|
|
272
|
-
return parquet.write(self.path, data)
|
|
273
|
-
case FileFormat.TSV:
|
|
274
|
-
return tsv.write(self.path, data)
|
|
275
|
-
case FileFormat.TXT:
|
|
276
|
-
return txt.write(self.path, data)
|
|
277
|
-
case FileFormat.XLS:
|
|
278
|
-
return xls.write(self.path, data)
|
|
279
|
-
case FileFormat.XLSX:
|
|
280
|
-
return xlsx.write(self.path, data)
|
|
281
|
-
case FileFormat.XML:
|
|
282
|
-
return xml.write(self.path, data, root_tag=root_tag)
|
|
283
|
-
case FileFormat.YAML:
|
|
284
|
-
return yaml.write(self.path, data)
|
|
285
|
-
case FileFormat.ZIP:
|
|
286
|
-
return zip_.write(self.path, data)
|
|
287
|
-
raise ValueError(f'Unsupported format: {fmt}')
|
|
314
|
+
writer = self._resolve_handler('write')
|
|
315
|
+
if not callable(writer):
|
|
316
|
+
raise TypeError(
|
|
317
|
+
f"'write' handler for format {self.file_format} "
|
|
318
|
+
'is not callable',
|
|
319
|
+
)
|
|
320
|
+
if _accepts_root_tag(writer):
|
|
321
|
+
return writer(self.path, data, root_tag=root_tag)
|
|
322
|
+
return writer(self.path, data)
|