Metadata-Version: 2.5
Name: due-extractor
Version: 0.9.0
Summary: DUE: Declarative Universal Extractor. Extract from any API into your data lake with no custom scripts.
Project-URL: Homepage, https://github.com/abhishekmanjunatha/due
Project-URL: Repository, https://github.com/abhishekmanjunatha/due
Project-URL: Changelog, https://github.com/abhishekmanjunatha/due/blob/main/docs/DUE_PLAN.md
Author: Abhishek Manjunatha
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: api,cdc,data-engineering,data-lake,elt,extraction
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Requires-Python: >=3.12
Requires-Dist: defusedxml>=0.7
Requires-Dist: fsspec>=2024.6
Requires-Dist: httpx>=0.27
Requires-Dist: jinja2>=3.1
Requires-Dist: jmespath>=1.0
Requires-Dist: pydantic>=2.8
Requires-Dist: pyyaml>=6.0
Requires-Dist: typer>=0.12
Provides-Extra: all
Requires-Dist: adlfs>=2024.4; extra == 'all'
Requires-Dist: azure-identity>=1.17; extra == 'all'
Requires-Dist: azure-keyvault-secrets>=4.8; extra == 'all'
Requires-Dist: backports-zstd>=1.0; (python_version < '3.14') and extra == 'all'
Requires-Dist: boto3>=1.34; extra == 'all'
Requires-Dist: duckdb>=1.0; extra == 'all'
Requires-Dist: fastavro>=1.9; extra == 'all'
Requires-Dist: gcsfs>=2024.6; extra == 'all'
Requires-Dist: google-cloud-secret-manager>=2.20; extra == 'all'
Requires-Dist: httpx[http2]>=0.27; extra == 'all'
Requires-Dist: keyring>=25; extra == 'all'
Requires-Dist: lxml>=5.2; extra == 'all'
Requires-Dist: openpyxl>=3.1; extra == 'all'
Requires-Dist: opentelemetry-exporter-otlp>=1.25; extra == 'all'
Requires-Dist: opentelemetry-sdk>=1.25; extra == 'all'
Requires-Dist: pyarrow>=16; extra == 'all'
Requires-Dist: ruamel-yaml>=0.18; extra == 'all'
Requires-Dist: s3fs>=2024.6; extra == 'all'
Requires-Dist: starlette>=0.38; extra == 'all'
Requires-Dist: uvicorn>=0.30; extra == 'all'
Requires-Dist: zstandard>=0.22; extra == 'all'
Provides-Extra: avro
Requires-Dist: fastavro>=1.9; extra == 'avro'
Provides-Extra: azure
Requires-Dist: adlfs>=2024.4; extra == 'azure'
Requires-Dist: azure-identity>=1.17; extra == 'azure'
Provides-Extra: excel
Requires-Dist: openpyxl>=3.1; extra == 'excel'
Provides-Extra: gcs
Requires-Dist: gcsfs>=2024.6; extra == 'gcs'
Provides-Extra: http2
Requires-Dist: httpx[http2]>=0.27; extra == 'http2'
Provides-Extra: keyring
Requires-Dist: keyring>=25; extra == 'keyring'
Provides-Extra: otel
Requires-Dist: opentelemetry-exporter-otlp>=1.25; extra == 'otel'
Requires-Dist: opentelemetry-sdk>=1.25; extra == 'otel'
Provides-Extra: parquet
Requires-Dist: pyarrow>=16; extra == 'parquet'
Provides-Extra: query
Requires-Dist: duckdb>=1.0; extra == 'query'
Provides-Extra: s3
Requires-Dist: s3fs>=2024.6; extra == 's3'
Provides-Extra: secrets-aws
Requires-Dist: boto3>=1.34; extra == 'secrets-aws'
Provides-Extra: secrets-azure
Requires-Dist: azure-identity>=1.17; extra == 'secrets-azure'
Requires-Dist: azure-keyvault-secrets>=4.8; extra == 'secrets-azure'
Provides-Extra: secrets-gcp
Requires-Dist: google-cloud-secret-manager>=2.20; extra == 'secrets-gcp'
Provides-Extra: ui
Requires-Dist: ruamel-yaml>=0.18; extra == 'ui'
Requires-Dist: starlette>=0.38; extra == 'ui'
Requires-Dist: uvicorn>=0.30; extra == 'ui'
Provides-Extra: xml
Requires-Dist: lxml>=5.2; extra == 'xml'
Provides-Extra: zstd
Requires-Dist: backports-zstd>=1.0; (python_version < '3.14') and extra == 'zstd'
Requires-Dist: zstandard>=0.22; extra == 'zstd'
Description-Content-Type: text/markdown

# DUE
<sub>by Abhishek Manjunatha</sub>

**Declarative Universal Extractor.** Extract from any API and land it in your data lake, with no custom scripts. DUE handles REST, GraphQL, XML/SOAP, files and report APIs, plus auth, pagination, rate limits, retries, safe incremental loads and deduplication. Records land unchanged in local storage, S3, GCS or ADLS. It is EL only: transformation belongs downstream.

> **Status: Phase 3 in progress. M1–M4 are done (release 0.3 is feature-complete); M5 (integrity and PII) is next.** Design approved, spec v1 frozen (2026-11-27). The plan and SDLC roadmap are in [docs/DUE_PLAN.md](docs/DUE_PLAN.md).

## Design (Phase 2 approved · spec v1 frozen)
- [High-level design](docs/design/HLD.md) · [Low-level design](docs/design/LLD.md) · [Spec v1 reference](docs/design/SPEC_V1.md)
- [UI wireframes](docs/design/UI_WIREFRAMES.md) · [Architecture decisions](docs/adr/README.md)
- [Sample connectors on real public APIs](connectors/)
- [Design review log and reviewer checklist](docs/design/REVIEW_LOG.md)

## What works today (M1–M4, release 0.3)
- `due validate`: checks a project (every profile) or a single source file against spec v1: unknown keys with "did you mean", file and line, secrets syntax, templates, hooks, and stream references.
- `due config show [source[.stream]]`: every effective setting and the layer it came from (defaults, project, profile, source, stream, env).
- `due spec fields [path] [-m]`: every spec field tagged `*` mandatory, `* when …` conditional, or optional (with its default), plus type, rules and description. The same catalog generates the [field reference](docs/design/SPEC_V1_FIELDS.md) and `due spec schema` (JSON Schema for editor autocomplete).
- `params:`: declare each `${NAME}` placeholder (required/optional, type, pattern, allowed values, min/max, secret). `due validate --check-secrets` checks the real values without printing secrets.
- `due --version`
- All defaults live in [`src/due/defaults.yaml`](src/due/defaults.yaml) (ADR-011). Override project settings with `DUE__SECTION__KEY=value`.

**M2 (HTTP core) is built.** It's a resilient async client: every auth type (API key, bearer, basic, OAuth2 client credentials, login chains, Python hooks), token-bucket and adaptive rate limiting (Retry-After, X-RateLimit-*, body backoff), retries with jittered backoff, a circuit breaker, safety limits, ETag/Last-Modified requests, corporate CA bundles, mTLS, proxies and optional HTTP/2. Secrets are redacted from every error.

**M3 (sources, pagination and decoders) is built.**
- **Stream types:** REST, GraphQL, SOAP, file downloads (streamed to disk), request → poll → download reports, and child streams.
- **Pagination:** all 7 styles, each guarded against loops.
- **Decoders:** JSON, NDJSON, CSV/TSV, XML (XPath, entity-attack protection), Excel, Parquet, text and zip/gzip archives.
- **Also:** matrix partitions and incremental windows.
- **`due preview source.stream`** fetches real records without writing anything.

17 example connectors on real public APIs are in [connectors/](connectors/).

**Release 0.1 is feature-complete:** `due run` extracts streams into a local lake (`file://`, NDJSON, gzip).
- **Commit protocol:** a failed run leaves nothing readable, a rerun replaces its window, and state never runs ahead of the data.
- **Duplicate check across overlapping windows.**
- **Lease locks,** plus `due unlock` for crashed runs.
- **`_rejected/`** for records without a key or cursor.
- **Explicit PII field actions** (hash, mask, drop).
- **A `_due_*` metadata column on every record.**

**Release 0.3 (M4) is feature-complete.**
- **Cloud lakes:** `s3://`, `gs://` and `abfs://` through fsspec (install `due-extractor[s3]`, `due-extractor[gcs]` or `due-extractor[azure]`).
- **Output formats:** NDJSON, CSV, Parquet and Avro, compressed with gzip, zstd or snappy.
- **Delete detection:** `deletes: { mode: snapshot_diff, every: 7d }` lands tombstones (`_due_op: delete`) for keys that disappeared.
- **Resume (G6):** a long extraction that dies continues from its last page checkpoint.
- **`matrix_from`:** partitions fed from another stream's records.
- **`due backfill src.stream --from … --to …`:** replaces those windows and never moves the watermark back.
- **Housekeeping:** `due retry RUN_ID` re-runs only failed units with their original windows; `due state show|reset`; `due prune` applies `retention`.
- **Crash suite:** tests kill a run at every commit step and check that no data is lost or duplicated and state never runs ahead (G1–G7).

**M5 (integrity and PII) is built**, and goes out in 0.5 together with M6:
- **Integrity checks:**
  - `reconcile_total` compares the fetched count with the API's own total, and is on automatically when the paginator reads one.
  - `min_records` catches a silent `200 []`.
  - `volume_collapse` warns when the count drops far below recent runs.
  - `max_rejected_ratio` limits keyless or unparseable records.
  - `fail` blocks the commit and keeps the previous data. `warn` commits and reports it.
- **PII detection** of emails, phone numbers, card numbers, tokens and IP addresses, before anything is written. A detected field gets `pii.default_action` and a `pii.detected` notice, so you can add an explicit `pii.fields` rule.

**M6 (alerting and observability) is built**, and released in **0.5** (`pipx install due-extractor`):
- **Alerts** to Slack, Microsoft Teams, Google Chat, Discord, PagerDuty, email (SMTP) or any webhook.
  - Rules decide which events go where.
  - `throttle` stops a flapping API from flooding a channel.
  - Each channel gets one grouped message per run.
- **Every run gets a self-contained HTML report** next to its summary. `due runs` lists history and `due report RUN_ID --open` opens one.
- **`observe.log_format: json`** prints one JSON event per line for log shippers.
- **OpenLineage** run events and **OpenTelemetry** metrics (the `otel` extra), both optional.

**M7 (developer tools) is built**, and released in **0.7** (`pipx install due-extractor`):
- **`due init --from-url | --from-curl | --from-har | --from-postman | --from-openapi`** drafts a source file. It suggests records, pagination, key, cursor and PII rules. Credentials become `${NAME}` placeholders.
- **`due doctor`** checks a stream against the live API: auth, pagination ends, page overlap, sort stability and rate headroom. **`due discover`** lists fields and suggests key, cursor and PII rules.
- **`due plan`** shows what a run will do and roughly how many requests it will take.
- **`due test record` / `due test replay`** records real responses once (secrets redacted, PII protected) and replays them offline in CI with assertions.
- **`due query "SQL"`** runs DuckDB over the lake's current data (`<source>__<stream>` and `…__latest` views). **`due diff RUN_A RUN_B`** compares two runs row by row.
- **`due schedule add|list|remove`** registers runs with cron or Windows Task Scheduler. **`due schedule export --to github-actions|airflow|cloud-scheduler|eventbridge`** writes a template.

**M8 (local UI) is built**, and released in **0.9** (`pipx install "due-extractor[ui]"`):
- **`due ui`** (`pip install "due-extractor[ui]"`) opens a local web UI on `127.0.0.1` only, signed in with a one-time token from the terminal.
- **New-source wizard:** paste a URL or curl command (or import OpenAPI, Postman or HAR). Then set auth, paging, records, keys, incremental loading, PII and integrity checks by clicking, with a live preview and doctor at each step. It saves plain YAML, and secrets go to the OS keyring or `.env`, never into the YAML.
- **Other screens:** a source editor, run now with live progress, run history and reports with Retry failed, schedules, and settings (destination, PII defaults, test alerts). Settings edits keep your comments.

## Install
```powershell
pipx install "due-extractor[parquet]"     # or: uv tool install due-extractor
due --version
```
The PyPI package is `due-extractor`; the command and the Python import are both `due`.

## Try it
```powershell
uv sync --group dev
uv run due validate connectors
uv run due config show usgs.earthquakes -C connectors -p cloud
uv run due spec fields source.auth --mandatory
uv run due preview wikipedia.recent_changes -C connectors -n 10
uv run due preview github.issues -C connectors --partition repo=pandas-dev/pandas
uv run due run ecb usgs -C connectors          # lands in connectors/lake/ (git-ignored)
uv run due run usgs -C connectors              # re-run: only the lookback overlap, unchanged records skipped
uv run due backfill github.issues --from 2026-11-01 --to 2026-11-08 -C connectors
uv run due state show usgs.earthquakes -C connectors
uv run due prune --dry-run -C connectors
uv run due runs -C connectors
uv run due init my-project --from-url "https://dummyjson.com/users?limit=30&skip=0"
uv run due doctor dummyjson.users -C my-project
uv run due query "SELECT count(*) FROM dummyjson__users__latest" -C my-project
uv run due ui -C my-project      # needs the [ui] extra (included in the dev group)
uv run due report <run_id> --open -C connectors
```

## Develop
```powershell
uv run ruff format src tests tools; uv run ruff check src tests tools
uv run mypy src tools
uv run python tools/check_hardcoding.py
uv run pytest --cov
uv run pytest -m live          # real public APIs (httpbin chaos tests); nightly in CI
```
CI runs the same gates on Windows, macOS and Linux with Python 3.12 and 3.14 ([ci.yml](.github/workflows/ci.yml)).

## Layout
- `src/due/`: the package (`spec/`, `secrets/`, `http/`, `paginate/`, `sources/`, `decode/`, `lake/` storage and writers, `run/` planner, runner and prune, `cli/`)
- `connectors/`: example project on real public APIs (also the validation fixture)
- `tests/`: unit tests
- `tools/`: repo tooling (the hard-coding lint)
- `docs/`: plan, design and ADRs
- `legacy/`: the old bk-pipeline code and its history, kept locally for reference only and **git-ignored**
