Pipelines API¶
earthcatalog.pipelines.incremental
¶
Single-node incremental ingest from an AWS S3 Inventory file.
Supported inventory formats¶
- CSV (plain or .gz) — AWS S3 Inventory default
- Parquet — AWS S3 Inventory optional output; preferred at scale (typed, compressed, no quoting ambiguity). Read in row-group batches so memory is bounded regardless of file size.
- manifest.json — AWS S3 Inventory manifest; references
multiple Parquet data files in a private
destination bucket. Pass the manifest URI
as
inventory_path; credentials for the destination bucket are read from~/.aws/credentials(default profile) or from theAWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEYenvironment variables.
The inventory must have at minimum two columns named bucket and key
(case-insensitive for CSV; exact for Parquet).
Delta ingestion¶
Pass since (a timezone-aware UTC datetime) to skip objects that
were last modified before that cutoff:
- Parquet: filters on the
last_modified_datecolumn; rows missing that column are passed through unchanged. The column may be either a string (ISO-8601) or a native Parquet TIMESTAMP — both are handled. - CSV: parses the
last_modified_datecolumn when a header row is present and the column is present; otherwise all rows are passed through (graceful degradation).
A typical 2-day delta run::
from datetime import datetime, timezone, timedelta
since = datetime.now(tz=timezone.utc) - timedelta(days=2)
run(inventory_path=..., since=since)
Memory notes¶
All S3 I/O goes through obstore. For S3 inventory files the full object
is downloaded once via obstore.get().bytes():
- Parquet:
pq.ParquetFile.iter_batches()then reads one row-group at a time — peak RAM is bounded bybatch_sizerows. - CSV.gz:
gzip.open(BytesIO(compressed_bytes))— only the compressed bytes are held; decompression is line-by-line. - CSV (plain):
TextIOWrapper(BytesIO(raw_bytes))— one copy of the raw bytes; no extra full-string decode. For very large plain-text inventories prefer CSV.gz or Parquet to halve the peak RAM.
True zero-copy streaming from the obstore async byte stream is a planned
improvement (obstore.GetResult.stream()); it would eliminate the full-file
download for all formats.
Usage
python -m earthcatalog.pipelines.incremental \ --inventory /tmp/test_inventory.csv \ --catalog /tmp/earthcatalog.db \ --warehouse /tmp/earthcatalog_warehouse \ --since 2026-04-21 \ --limit 500
Using a real S3 Inventory manifest (requires AWS credentials):¶
python -m earthcatalog.pipelines.incremental \ --inventory s3://my-log-bucket/inventory/.../manifest.json \ --catalog /tmp/earthcatalog.db \ --warehouse /tmp/earthcatalog_warehouse \ --since 2026-04-21
Classes¶
Functions¶
run(inventory_path, catalog_path, warehouse_path, chunk_size=500, max_workers=16, limit=None, h3_resolution=1, partitioner=None, use_lock=True, batch_add_files=False, since=None, grid_config=None)
¶
Read inventory → fetch STAC JSON from S3 in parallel → fan_out() → write_geoparquet() → add_files() to PyIceberg table.
Each (grid_partition, year) group is written as a separate GeoParquet
file in hive-style layout. Files are registered in the Iceberg catalog via
table.add_files().
Parameters¶
since:
When set (timezone-aware UTC), only inventory rows with
last_modified_date >= since are processed. Pass
datetime.now(tz=timezone.utc) - timedelta(days=2) for a
2-day delta run. None processes the full inventory.
batch_add_files:
When False (default), table.add_files() is called after every
chunk — one Iceberg snapshot per chunk. Safe for incremental daily
runs: a mid-run crash leaves the catalog in a consistent partial state.
When ``True``, all GeoParquet paths are collected and registered in a
**single** ``table.add_files()`` call at the very end — exactly one
Iceberg snapshot regardless of how many chunks were processed. Use
this for initial backfills to prevent snapshot explosion.
If the process crashes mid-run, no files are registered; re-run from
scratch.
The full run is wrapped in an S3Lock (set use_lock=False for tests).
download_catalog / upload_catalog are called inside the lock so
the SQLite catalog.db is safely synchronised with the configured store.
Source code in earthcatalog/pipelines/incremental.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
run_from_config(inventory_path, config, limit=None)
¶
Drive the incremental pipeline from an AppConfig instance.
Parameters¶
inventory_path:
Local path or s3:// URI to the S3 Inventory CSV, CSV.gz, or
Parquet file.
config:
An :class:earthcatalog.config.AppConfig instance.
limit:
Optional cap on the number of STAC items processed (for testing).
Source code in earthcatalog/pipelines/incremental.py
earthcatalog.pipelines.backfill
¶
Staging-based backfill pipeline for earthcatalog.
Architecture (four phases, fully idempotent)¶
Phase 1 — Scheduler (head node)
Reads the inventory manifest/CSV/Parquet and writes fixed-size chunk
files (Parquet, one row per .stac.json item) to a staging prefix.
Each chunk contains up to chunk_size (bucket, key) pairs.
Already-written chunks are skipped on restart (idempotent).
Phase 2 — Ingest (one Dask task per chunk)
Each worker:
1. Reads its chunk Parquet from the staging store.
2. Async-fetches all STAC JSONs using obstore.get_async with a
TaskGroup + Semaphore.
3. Accumulates items in memory, fans out through the H3 partitioner.
4. Writes each (cell, year) group as NDJSON to:
staging/{cell}/{year}/chunk_{id}.ndjson
Phase 3 — Compact (one Dask task per (cell, year))
Each worker:
1. Scans the staging prefix for ALL .ndjson files in its bucket.
2. Reads them into memory, deduplicates by id.
3. Writes up to compact_rows rows per GeoParquet file.
4. Does NOT delete NDJSON staging files (Phase 4 does that).
Phase 4 — Register (head node)
1. Drops and recreates the Iceberg table.
2. Registers all warehouse Parquet files via table.add_files().
3. Uploads the catalog.
4. Deletes all staging files.
Delta mode (delta=True)¶
Lightweight append-only path for small incremental ingests.
Phase 3 — Delta Compact Same as normal compact (NDJSON → GeoParquet) but output files are numbered starting from the next available index in the warehouse partition, so existing parquets are never overwritten.
Phase 4 — Delta Register
Opens the existing Iceberg table (no drop) and calls
table.add_files() with only the newly written parquets.
Spot resilience¶
Every phase is individually idempotent. If a spot instance is killed:
- Phase 1: chunks already written survive; scheduler skips them.
- Phase 2: NDJSON files written by dead workers survive and are picked up by Phase 3 on the next run.
- Phase 3: each (cell, year) task scans S3 fresh.
- Phase 4: catalog is rebuilt from scratch (drop + recreate).
Classes¶
Functions¶
write_chunks(inventory_path, staging_store, staging_prefix, chunk_size=100000, limit=None, since=None, write_concurrency=8)
¶
Read inventory and write chunk Parquet files to the staging store.
Streams from the inventory iterator into chunk-sized buffers and writes each chunk as soon as it's full — no need to materialize the entire inventory in memory.
Already-written chunks are detected via a single obstore.list call
upfront. Items belonging to existing chunks are still consumed from the
inventory iterator but not buffered or written.
Writes are parallelized with a thread pool.
Returns list of chunk keys (including pre-existing ones).
Source code in earthcatalog/pipelines/backfill.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
ingest_chunk(chunk_key, staging_store, staging_prefix, pending_prefix, partitioner, fetch_concurrency=_FETCH_CONCURRENCY)
¶
Phase 2 worker: read chunk → fetch items → fan-out → write NDJSON groups.
Failed items are written to pending_prefix/chunk_{id}.parquet for
retry on the next run. If all items succeed, no pending file is created.
Returns a report dict with counts and the list of NDJSON keys written.
Source code in earthcatalog/pipelines/backfill.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
compact_cell_year(cell, year, staging_store, staging_prefix, warehouse_store, compact_rows=100000)
¶
Phase 3 worker: stream NDJSON → write GeoParquet to warehouse_store.
Source code in earthcatalog/pipelines/backfill.py
compact_cell_year_delta(cell, year, staging_store, staging_prefix, warehouse_store, compact_rows=100000)
¶
Phase 3 delta worker: compact NDJSON → new GeoParquet (no overwrite).
Source code in earthcatalog/pipelines/backfill.py
register_and_cleanup(catalog_path, warehouse_root, staging_store, staging_prefix, warehouse_store=None, upload=True, h3_resolution=None, hash_index_path=None)
¶
Phase 4: rebuild Iceberg catalog from warehouse files, upload, cleanup staging.
- Drop and recreate the Iceberg table.
- Scan warehouse for all Parquet files.
- Register via table.add_files().
- Upload catalog.
- Delete all staging files.
hash_index_path defaults to {warehouse_root}_id_hashes.parquet.
When warehouse_store is provided it is used for store-based listing instead of local filesystem glob (which was the pre-Phase-C fallback).
Source code in earthcatalog/pipelines/backfill.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | |
register_delta(catalog_path, warehouse_root, new_parquet_paths, staging_store, staging_prefix, upload=True, h3_resolution=None, hash_index_path=None, update_hash_index=False)
¶
Phase 4 delta: add new parquet files to existing Iceberg table (no drop).
Opens (or creates) the Iceberg table, calls table.add_files()
with only the newly written parquets, then uploads the catalog.
Existing warehouse files are never touched.
When update_hash_index is True, the warehouse hash index is updated
by reading the id column from each newly written parquet file,
hashing each ID, and merging into the existing index. This is Plan B:
read from the actual warehouse files that were just registered, so the
index exactly reflects what is in the catalog.
hash_index_path defaults to {warehouse_root}_id_hashes.parquet.
Source code in earthcatalog/pipelines/backfill.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 | |
cleanup_staging(staging_store, staging_prefix)
¶
Delete completion markers and pending files. Keeps chunks and NDJSON.
Source code in earthcatalog/pipelines/backfill.py
run_backfill(inventory_path, catalog_path, staging_store, staging_prefix, warehouse_store, warehouse_root, partitioner=None, h3_resolution=None, chunk_size=100000, compact_rows=100000, fetch_concurrency=256, limit=None, since=None, use_lock=True, upload=True, skip_inventory=False, skip_ingest=False, retry_pending=False, delta=False, create_client=None, hash_index_path=None, update_hash_index=False)
¶
Four-phase staging-based backfill pipeline.
Parameters¶
inventory_path:
Local path or s3:// URI to inventory (CSV, Parquet, or manifest.json).
catalog_path:
Local path for SQLite catalog.
staging_store:
obstore-compatible store for staging (chunks + NDJSON).
staging_prefix:
Key prefix within staging_store (e.g. "ingest").
warehouse_store:
obstore-compatible store for warehouse GeoParquet output.
Unused for local filesystem (warehouse_root is used directly).
warehouse_root:
Path or s3:// URI for the warehouse root (used by add_files).
partitioner:
H3Partitioner or similar. When None, the partitioner is built from
h3_resolution (see below).
h3_resolution:
H3 resolution for the default partitioner. When None the resolution
is read from the existing Iceberg table's properties. If the table
does not exist yet and no resolution is given, a ValueError is
raised.
chunk_size:
Items per chunk Parquet in Phase 1.
compact_rows:
Max rows per output GeoParquet file in Phase 3.
skip_ingest:
If True, skip Phase 2 entirely and go straight to Phase 3 (Compact).
Phase 3 scans S3 for existing NDJSON files. Useful when Phase 2 already
completed but Phase 3 needs to be re-run (e.g. with bigger instances).
retry_pending:
If True, Phase 2 retries chunks that had fetch failures (stored in
pending_chunks/). If False (default), pending chunks are logged but
skipped — Phase 3 proceeds with whatever succeeded.
delta:
If True, run in delta mode: Phase 3 writes new parquets without
overwriting existing ones, and Phase 4 adds files to the existing
Iceberg table instead of dropping and recreating it.
create_client:
Optional callable that returns a Dask Client. Called lazily
right before Phase 2 (after Phase 1 completes). Used for
Coiled to avoid idle cluster timeout during long Phase 1 runs.
Source code in earthcatalog/pipelines/backfill.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 | |