Build a typed Python ETL pipeline with configuration, retries for transient failures, structured logging, chunked processing, idempotent loads and tests.
You are a Python data engineer. Build a data pipeline for the specification below. It must be safe to rerun, observable through logs, and testable without production systems. ## Inputs Source (database, API or files), access method and volume: [SOURCE] Transformations and business rules: [TRANSFORMATIONS] Destination and its schema: [DESTINATION] Schedule and orchestrator (cron, Airflow, Dagster, none): [SCHEDULE] Python version and allowed libraries: [ENVIRONMENT] Failure expectations (rate limits, flaky network, malformed records): [FAILURE_MODES] ## Instructions 1. Structure the code as extract, transform and load functions or classes with type hints, wired by a small entry point. 2. Read configuration from a file or environment variables; keep secrets in environment variables only. 3. Retry only transient failures (timeouts, 429/5xx responses, dropped connections) with exponential backoff and a maximum attempt count. Do not retry validation errors. 4. Validate records against the destination schema; send invalid records to a quarantine output with the reason. 5. Process data in chunks or streams sized for available memory. 6. Make loads idempotent: upsert on a natural or source key, or load into a staging table and swap. A rerun of the same window must not duplicate data. 7. Log structured events (run ID, step, counts read/written/rejected, duration). Exit non-zero on failure. 8. Write unit tests for transformations and an integration test against a local or in-memory destination. ## Return 1. Main pipeline module. 2. Helper utilities (retry, chunking, logging setup). 3. Config file template. 4. Example usage and the command to run it. 5. `requirements.txt` with pinned versions you name as examples to confirm. 6. Tests. 7. Operational notes: backfills, reruns, monitoring. ## Acceptance checks - Running the same window twice leaves the destination unchanged. - Retries are limited to transient errors and capped. - Rejected records are counted and stored, not dropped. - No credentials in code or config templates.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Source: paginated REST API GET /v1/invoices?updated_since=...&page=..., bearer token, about 30,000 invoices per day, rate limit 10 requests/second with 429 responses Transformations: convert amounts from strings to integer cents, map status codes to open|paid|void, drop test accounts (account_id starting with "TEST-") Destination: PostgreSQL table invoices(invoice_id PK, account_id, status, amount_cents, updated_at) Schedule: hourly cron, processing records updated since the last successful run Environment: Python 3.12; httpx, psycopg 3, pydantic 2 allowed Failures: occasional 429 and 503 responses; some invoices have malformed amounts
A pipeline with an httpx extractor that follows pages, retries 429/503 with capped exponential backoff and respects Retry-After; a pydantic model that converts amounts to cents and quarantines malformed amounts with reasons; a filter for TEST- accounts with a logged count; INSERT ... ON CONFLICT (invoice_id) DO UPDATE for idempotent loads; a high-water mark saved only after a successful load; structured logs with run ID and counts; and tests for the transformation and for rerunning the same window. Illustrative expectation; the rerun-idempotency pattern was executed locally against SQLite on a synthetic fixture (see report).
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
IDEs
Models