Metadata-Version: 2.5
Name: icetrace
Version: 0.2.0
Summary: Scan-planning & metadata forensics engine for Apache Iceberg — EXPLAIN ANALYZE for Iceberg metadata without Spark.
Project-URL: Homepage, https://github.com/sanspareilsmyn/icetrace
Project-URL: Repository, https://github.com/sanspareilsmyn/icetrace
Project-URL: Issues, https://github.com/sanspareilsmyn/icetrace/issues
Project-URL: Changelog, https://github.com/sanspareilsmyn/icetrace/blob/main/CHANGELOG.md
Author-email: Sangmin Yoon <sanspareilsmyn@users.noreply.github.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: apache-iceberg,data-engineering,forensics,iceberg,lakehouse,mcp,metadata,query-planning
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Debuggers
Requires-Python: >=3.11
Requires-Dist: mcp>=2.0.0
Requires-Dist: pyarrow>=16.0.0
Requires-Dist: pydantic>=2.7.0
Requires-Dist: pyiceberg[sql-sqlite]>=0.9.0
Requires-Dist: rich>=13.7.0
Requires-Dist: sqlglot>=25.0.0
Requires-Dist: typer>=0.12.0
Provides-Extra: all
Requires-Dist: pyiceberg[gcsfs,glue,hive,s3fs,sql-postgres]>=0.9.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: mypy>=1.11.0; extra == 'dev'
Requires-Dist: pyarrow>=16.0.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest>=8.2.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Provides-Extra: gcs
Requires-Dist: pyiceberg[gcsfs]>=0.9.0; extra == 'gcs'
Provides-Extra: glue
Requires-Dist: pyiceberg[glue,s3fs]>=0.9.0; extra == 'glue'
Provides-Extra: hive
Requires-Dist: pyiceberg[hive]>=0.9.0; extra == 'hive'
Provides-Extra: s3
Requires-Dist: pyiceberg[s3fs]>=0.9.0; extra == 's3'
Description-Content-Type: text/markdown

# icetrace

**X-ray your Apache Iceberg tables in 10 seconds without Spark — find silent pruning bugs, wasted snapshot storage, and exact fix ROI.**

[![PyPI](https://img.shields.io/pypi/v/icetrace.svg)](https://pypi.org/project/icetrace/)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)

Your Iceberg tables look healthy — 256 MB files, compaction enabled — yet queries still scan 95% of the data, and un-expired snapshots quietly leak terabytes of S3 storage.

`icetrace` reads **only Iceberg metadata** (never Parquet data files, strictly read-only, 16-way concurrent Avro reads). Point it at your AWS Glue or REST catalog and in seconds it:

1. **X-Rays your entire database (`icetrace scan`)** — ranks your worst-pruning, highest-waste tables `0–100` without typing a single SQL query.
2. **Simulates Iceberg's 4-stage scan planner (`icetrace explain`)** — proves *why* files weren't pruned (`MISSING_METRICS_COL_LIMIT` past col #32, `truncate(16)` prefix collisions, `OVERLAPPING_RANGES`, evolved partition specs).
3. **Quantifies storage waste & What-If ROI (`icetrace roi`)** — exact reclaimable S3 GB/month from historical snapshots + projected Athena scan reduction (`%` & `$/mo`) before you pay for a Spark rewrite.

---

## Try It in 5 Seconds (Zero Credentials Required)

```bash
uvx icetrace demo
```

```text
Predicate: tenant_id = 'org_prod_us_east_03_0042'

Stage 1  Manifest List     8 evaluated ──▶ 0 pruned ──▶ 8 surviving  (0.0%)
Stage 2  Partitions        8 evaluated ──▶ 0 pruned ──▶ 8 surviving  (0.0%)
Stage 3  Column Bounds     8 evaluated ──▶ 0 pruned ──▶ 8 surviving  (0.0%)

Root Cause: TRUNCATED_BOUNDS (8/8 files)
  tenant_id uses Iceberg's default truncate(16). All 8 files share prefix
  'org_prod_us_east', collapsing min/max bounds and disabling data skipping.
```

```text
Per-Column Pruning Readiness (O(N log N) Domain-Weighted Sweep-Line)
  #   Column      Mode          Bounds   Overlap   Trunc%   Grade
  1   event_id    truncate(16)    100%      0.00       0%     A    ✓ well-sorted
  2   tenant_id   truncate(16)    100%      1.00     100%     F    ✗ truncate(16) collision
  3   amount      truncate(16)    100%      0.98       0%     F    ✗ overlapping ranges
 35   trace_key   none              0%         -       0%     F    ✗ past 32-col metrics cutoff
```

---

## X-Ray Your Entire Catalog in One Command

```bash
# Scan an entire Glue / REST database (strictly read-only, metadata-only)
ICETRACE_CATALOG_TYPE=glue icetrace scan --namespace analytics

# Simulate What-If ROI before running expensive compaction
ICETRACE_CATALOG_TYPE=glue icetrace roi analytics.events

# Explain why a specific WHERE clause scanned too much data
ICETRACE_CATALOG_TYPE=glue icetrace explain analytics.events \
  --where "event_ts >= '2026-11-20' AND tenant_id = 'org_prod_01'"
```

---

## Use Inside Cursor or Claude Code (MCP)

Ask your agent directly while your SQL, dbt model, or table DDL is open:

> *"Run `scan_catalog` on `analytics` and show me the top 3 tables wasting the most scan bytes or S3 storage."*  
> *"Run `explain_scan` on `analytics.events` for `WHERE tenant_id = 'org_prod_8491'`. Why did Athena scan 180 GB?"*

**Claude Code:**
```bash
claude mcp add --transport stdio --scope user icetrace -- uvx --from "icetrace[glue]" icetrace-mcp
```

**Cursor** (`.cursor/mcp.json` or `~/.cursor/mcp.json`):
```json
{
  "mcpServers": {
    "icetrace": {
      "command": "uvx",
      "args": ["--from", "icetrace[glue]", "icetrace-mcp"],
      "env": {
        "ICETRACE_CATALOG_TYPE": "glue",
        "AWS_PROFILE": "${env:AWS_PROFILE}",
        "AWS_REGION": "us-east-1"
      }
    }
  }
}
```

Works with **AWS Glue**, **REST Catalogs** (Polaris, Lakekeeper, Nessie, Unity, S3 Tables), **Hive**, and **SQL** via `~/.pyiceberg.yaml` or `ICETRACE_CATALOG_TYPE` env vars.

---

## Install

```bash
# Zero-install
uvx icetrace demo

# Homebrew (macOS / Linux)
brew tap sanspareilsmyn/icetrace https://github.com/sanspareilsmyn/icetrace
brew install icetrace

# uv tool (with AWS Glue & S3)
uv tool install "icetrace[glue]"
```

---

## 7 Read-Only Forensic Tools (CLI & MCP)

| CLI / MCP Tool | What It Proves (Metadata Only) |
|---|---|
| `scan` / `scan_catalog` | Concurrently X-Rays all tables in a namespace/catalog, scores each `0–100`, and ranks worst offenders by pruning bugs & reclaimable storage. |
| `explain` / `explain_scan` | 4-stage scan-planning simulator (100% parity with PyIceberg `plan_files()`) + per-file survival root-cause attribution (6 root causes). |
| `roi` / `simulate_roi` | Historical snapshot storage waste (S3 GB & `$/mo`) + What-If scan reduction (`%` & Athena `$/mo`) for sort compaction, full metrics, and manifest rewrites. |
| `audit` / `audit_pruning_health` | Per-column bounds coverage, `truncate(N)` collision %, $O(N \log N)$ sweep-line overlap ratio, manifest interleaving, small files, and V2/V3 delete amplification. |
| `diff` / `diff_snapshots` | Pinpoints which snapshot spiked manifests, dropped bounds coverage, or regressed pruning for a query. |
| `inspect` / `inspect_table_layout` | Instant `metadata.json` dump (zero manifest reads): format version, column ordinals & resolved metrics modes, evolved partition specs, sort order. |
| `tables` / `list_tables` | Catalog/namespace discovery. |

---

## Safety Guarantees

- **Strictly Read-Only:** Never mutates, compacts, or expires tables (`readOnlyHint: true`, `destructiveHint: false` on all 7 MCP tools).
- **Metadata-Only:** Only reads `metadata.json`, manifest lists, and manifest Avro files — never scans Parquet/ORC data.
- **Bounded Cost:** Enforces `max_manifests` guardrails so huge production tables never hang or burn S3 GETs.
- **Local & Zero-Telemetry:** Credentials and metadata never leave your machine.

---

[Roadmap](ROADMAP.md) · [Changelog](CHANGELOG.md) · [Agent Skill](skills/icetrace/SKILL.md) · [Contributing](CONTRIBUTING.md) · Apache-2.0
