col-reaper 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sanjay Kandimalla
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,385 @@
1
+ Metadata-Version: 2.4
2
+ Name: col-reaper
3
+ Version: 0.1.0
4
+ Summary: Find dead columns in your data warehouse — columns nobody has queried in days
5
+ Author-email: Sanjay Kandimalla <sanjay99llxx@users.noreply.github.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/codewithsanjay-pixel/col-reaper
8
+ Project-URL: Repository, https://github.com/codewithsanjay-pixel/col-reaper
9
+ Project-URL: Issues, https://github.com/codewithsanjay-pixel/col-reaper/issues
10
+ Keywords: data-engineering,snowflake,bigquery,dead-columns,data-warehouse,schema
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Information Technology
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: click>=8.0
26
+ Requires-Dist: rich>=13.0
27
+ Requires-Dist: sqlglot>=23.0
28
+ Provides-Extra: snowflake
29
+ Requires-Dist: snowflake-connector-python>=3.0; extra == "snowflake"
30
+ Provides-Extra: bigquery
31
+ Requires-Dist: google-cloud-bigquery>=3.0; extra == "bigquery"
32
+ Provides-Extra: all
33
+ Requires-Dist: snowflake-connector-python>=3.0; extra == "all"
34
+ Requires-Dist: google-cloud-bigquery>=3.0; extra == "all"
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=7.0; extra == "dev"
37
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
38
+ Requires-Dist: ruff>=0.1; extra == "dev"
39
+ Dynamic: license-file
40
+
41
+ # ⚰ col-reaper
42
+
43
+ **Find dead columns in your data warehouse. Drop what nobody uses.**
44
+
45
+ [![CI](https://github.com/codewithsanjay-pixel/col-reaper/actions/workflows/ci.yml/badge.svg)](https://github.com/codewithsanjay-pixel/col-reaper/actions)
46
+ [![PyPI](https://img.shields.io/pypi/v/col-reaper.svg)](https://pypi.org/project/col-reaper/)
47
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://python.org)
48
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
49
+
50
+ col-reaper scans your Snowflake or BigQuery query history and finds columns that
51
+ nobody has queried recently. It outputs a report and a ready-to-run SQL migration
52
+ script so your team can safely clean up the schema.
53
+
54
+ **Zero data leaves your warehouse.** col-reaper is strictly read-only and only
55
+ reads column metadata and query text — never your actual data.
56
+
57
+ ---
58
+
59
+ ## Why col-reaper?
60
+
61
+ Over time, data warehouses accumulate **ghost columns** — columns created for a
62
+ one-off analysis, a deprecated feature, or a migration that never finished. These
63
+ columns:
64
+
65
+ - **Cost money** — cloud warehouses charge for storage and scan bytes
66
+ - **Slow down queries** — wider tables = more bytes scanned per full scan
67
+ - **Confuse analysts** — "is `referral_source_v1` or `referral_source_v2` correct?"
68
+ - **Hide in plain sight** — no warehouse has a built-in "who uses this column?" view
69
+
70
+ col-reaper fills that gap.
71
+
72
+ ---
73
+
74
+ ## Try it in 30 seconds (no credentials needed)
75
+
76
+ ```bash
77
+ pip install col-reaper
78
+
79
+ # Run the demo — synthetic e-commerce data, no warehouse required
80
+ col-reaper demo
81
+
82
+ # See it as HTML
83
+ col-reaper demo --format html --output demo.html && open demo.html
84
+
85
+ # See the migration SQL
86
+ col-reaper demo --format sql
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Installation
92
+
93
+ ```bash
94
+ # Base install (demo mode + all analysis, no warehouse drivers)
95
+ pip install col-reaper
96
+
97
+ # With Snowflake support
98
+ pip install "col-reaper[snowflake]"
99
+
100
+ # With BigQuery support
101
+ pip install "col-reaper[bigquery]"
102
+
103
+ # Everything
104
+ pip install "col-reaper[all]"
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Quick start
110
+
111
+ ### Snowflake
112
+
113
+ ```bash
114
+ export SNOWFLAKE_ACCOUNT=xy12345.us-east-1
115
+ export SNOWFLAKE_USER=col_reaper_svc
116
+ export SNOWFLAKE_PASSWORD=...
117
+ export SNOWFLAKE_DATABASE=ANALYTICS
118
+ export SNOWFLAKE_WAREHOUSE=COMPUTE_WH
119
+
120
+ # Scan — terminal report
121
+ col-reaper scan --warehouse snowflake --days 90
122
+
123
+ # Scan with dry-run (review before committing to drops)
124
+ col-reaper scan --warehouse snowflake --days 90 --dry-run --format sql
125
+
126
+ # Generate migration SQL
127
+ col-reaper scan --warehouse snowflake --days 90 --format sql --output cleanup.sql
128
+
129
+ # Shareable HTML report
130
+ col-reaper scan --warehouse snowflake --days 90 --format html --output report.html
131
+ ```
132
+
133
+ ### BigQuery
134
+
135
+ ```bash
136
+ export GOOGLE_CLOUD_PROJECT=my-gcp-project
137
+ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
138
+
139
+ col-reaper scan --warehouse bigquery --days 90
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Output formats
145
+
146
+ ### `terminal` (default) — rich colour table
147
+
148
+ ```
149
+ ⚰ col-reaper | ANALYTICS | lookback: 90d | found: 7 dead columns
150
+
151
+ ╭──────────┬────────────────┬─────────────────────┬─────────┬────────────┬────────────╮
152
+ │ Schema │ Table │ Column │ Type │ Last Seen │ Confidence │
153
+ ├──────────┼────────────────┼─────────────────────┼─────────┼────────────┼────────────┤
154
+ │ PUBLIC │ USERS │ referral_source │ VARCHAR │ never │ high │
155
+ │ PUBLIC │ USERS │ legacy_user_flag │ BOOLEAN │ never │ high │
156
+ │ PUBLIC │ ORDERS │ shipping_v1_address │ VARCHAR │ never │ high │
157
+ ╰──────────┴────────────────┴─────────────────────┴─────────┴────────────┴────────────╯
158
+ ```
159
+
160
+ ### `sql` — ready-to-run migration script
161
+
162
+ ```sql
163
+ -- col-reaper migration script
164
+ -- Warehouse : ANALYTICS (snowflake)
165
+ -- Generated : 2026-11-01 09:30 UTC
166
+ -- Lookback : 90 days
167
+ -- REVIEW CAREFULLY before running.
168
+
169
+ -- Table: ANALYTICS.PUBLIC.USERS
170
+ ALTER TABLE ANALYTICS.PUBLIC.USERS DROP COLUMN referral_source;
171
+ ALTER TABLE ANALYTICS.PUBLIC.USERS DROP COLUMN legacy_user_flag;
172
+
173
+ -- Table: ANALYTICS.PUBLIC.ORDERS
174
+ ALTER TABLE ANALYTICS.PUBLIC.ORDERS DROP COLUMN shipping_v1_address;
175
+ ```
176
+
177
+ ### `sql` with `--dry-run` — deprecation comments (safe review mode)
178
+
179
+ ```sql
180
+ -- col-reaper DRY RUN — deprecation comments only
181
+ -- Step 1: Paste these comments into your migration tool to mark columns.
182
+ -- Step 2: Monitor for 30 days. If no complaints, re-run without --dry-run.
183
+
184
+ -- Table: ANALYTICS.PUBLIC.USERS
185
+ -- [DEPRECATED 2026-11-01] ANALYTICS.PUBLIC.USERS.referral_source — not queried in 90 days (confidence: high). Review before dropping.
186
+ -- [DEPRECATED 2026-11-01] ANALYTICS.PUBLIC.USERS.legacy_user_flag — not queried in 90 days (confidence: high). Review before dropping.
187
+ ```
188
+
189
+ ### `json` — machine-readable
190
+
191
+ ```json
192
+ {
193
+ "meta": {
194
+ "generated_at": "2026-11-01T09:30:00+00:00",
195
+ "warehouse": "snowflake",
196
+ "lookback_days": 90,
197
+ "dead_column_count": 7,
198
+ "dry_run": false
199
+ },
200
+ "dead_columns": [
201
+ {
202
+ "database": "ANALYTICS",
203
+ "schema": "PUBLIC",
204
+ "table": "USERS",
205
+ "column": "referral_source",
206
+ "data_type": "VARCHAR",
207
+ "last_seen": null,
208
+ "days_since_last_use": null,
209
+ "confidence": "high",
210
+ "drop_statement": "ALTER TABLE ANALYTICS.PUBLIC.USERS DROP COLUMN referral_source;"
211
+ }
212
+ ]
213
+ }
214
+ ```
215
+
216
+ ### `html` — shareable report with filtering and sorting
217
+
218
+ ```bash
219
+ col-reaper scan --warehouse snowflake --format html --output report.html
220
+ # Open report.html in any browser — no server needed, fully self-contained
221
+ ```
222
+
223
+ The HTML report includes:
224
+ - Summary stats (dead count, confidence breakdown)
225
+ - Filterable, sortable table
226
+ - One-click copy of the DROP statement per column
227
+ - Dark theme, works offline
228
+
229
+ ### `markdown` — paste into GitHub / Slack / Notion
230
+
231
+ ```bash
232
+ col-reaper scan --warehouse snowflake --format markdown
233
+ ```
234
+
235
+ ---
236
+
237
+ ## Dry-run mode
238
+
239
+ **Always run with `--dry-run` first.**
240
+
241
+ Dry-run mode outputs review comments instead of DROP statements. Use it to:
242
+ 1. Share the list with your team for review
243
+ 2. Watch for complaints for 30 days (BI tools, notebooks, apps)
244
+ 3. Only then run the real migration
245
+
246
+ ```bash
247
+ # Step 1: Review
248
+ col-reaper scan --warehouse snowflake --days 90 --dry-run --format sql --output review.sql
249
+
250
+ # Step 2 (after 30+ days): Actually drop
251
+ col-reaper scan --warehouse snowflake --days 90 --format sql --output cleanup.sql
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Filtering
257
+
258
+ ```bash
259
+ # Skip entire schemas
260
+ col-reaper scan --warehouse snowflake --exclude-schema STAGING --exclude-schema RAW
261
+
262
+ # Skip specific tables
263
+ col-reaper scan --warehouse snowflake --exclude-table TEMP_MIGRATION
264
+
265
+ # Skip columns matching a pattern (substring, case-insensitive)
266
+ col-reaper scan --warehouse snowflake --exclude-column _deprecated --exclude-column legacy_
267
+
268
+ # Combine filters
269
+ col-reaper scan --warehouse snowflake \
270
+ --exclude-schema STAGING \
271
+ --exclude-column _v1 \
272
+ --days 60
273
+ ```
274
+
275
+ ---
276
+
277
+ ## CI/CD integration
278
+
279
+ Add col-reaper to your CI pipeline to enforce a maximum number of dead columns:
280
+
281
+ ```yaml
282
+ # .github/workflows/warehouse-hygiene.yml
283
+ name: Warehouse hygiene check
284
+ on:
285
+ schedule:
286
+ - cron: '0 9 * * 1' # every Monday at 9am UTC
287
+ workflow_dispatch:
288
+
289
+ jobs:
290
+ col-reaper:
291
+ runs-on: ubuntu-latest
292
+ steps:
293
+ - uses: actions/checkout@v4
294
+
295
+ - name: Install col-reaper
296
+ run: pip install "col-reaper[snowflake]"
297
+
298
+ - name: Scan for dead columns
299
+ env:
300
+ SNOWFLAKE_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
301
+ SNOWFLAKE_USER: ${{ secrets.SNOWFLAKE_USER }}
302
+ SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
303
+ SNOWFLAKE_DATABASE: ANALYTICS
304
+ SNOWFLAKE_WAREHOUSE: COMPUTE_WH
305
+ run: |
306
+ col-reaper scan \
307
+ --warehouse snowflake \
308
+ --days 90 \
309
+ --exclude-schema STAGING \
310
+ --format markdown \
311
+ --output dead-columns.md
312
+
313
+ - name: Upload report
314
+ uses: actions/upload-artifact@v4
315
+ with:
316
+ name: dead-columns-report
317
+ path: dead-columns.md
318
+
319
+ # Optional: fail the build if dead columns are found
320
+ # - name: Fail if dead columns exist
321
+ # run: col-reaper scan --warehouse snowflake --days 90 --fail-on-found
322
+ ```
323
+
324
+ ---
325
+
326
+ ## How it works
327
+
328
+ 1. **Fetch schema** — col-reaper reads `INFORMATION_SCHEMA.COLUMNS` to get every column in scope (read-only, metadata only).
329
+
330
+ 2. **Fetch query history** — it reads recent SELECT queries from:
331
+ - Snowflake: `SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY` (365-day history, requires IMPORTED PRIVILEGES on SNOWFLAKE DB) — falls back to `INFORMATION_SCHEMA.QUERY_HISTORY` (7-day history, no special grants needed)
332
+ - BigQuery: `region-us.INFORMATION_SCHEMA.JOBS_BY_PROJECT`
333
+
334
+ 3. **Parse SQL** — each query's text is parsed with [sqlglot](https://github.com/tobymao/sqlglot) to extract every column reference. A regex fallback handles edge cases.
335
+
336
+ 4. **Dead = not referenced** — a column is "dead" if it appears in zero parsed queries. A confidence score (high/medium/low) accounts for ambiguous short names.
337
+
338
+ 5. **Report** — results are rendered in your chosen format with optional DROP statements.
339
+
340
+ ---
341
+
342
+ ## Confidence scores
343
+
344
+ | Score | Meaning | Example column names |
345
+ |-------|---------|----------------------|
346
+ | **high** | Specific name, low false-positive risk | `shipping_v1_address`, `fb_pixel_id_deprecated` |
347
+ | **medium** | Short name (≤ 3 chars), slightly ambiguous | `qty`, `sku`, `ref` |
348
+ | **low** | Very common name — might match unrelated queries | `id`, `name`, `created_at` |
349
+
350
+ **Recommendation:** review "low" confidence columns manually before dropping.
351
+
352
+ ---
353
+
354
+ ## Security
355
+
356
+ col-reaper is **strictly read-only**. It never writes anything to your warehouse.
357
+
358
+ See [SECURITY.md](SECURITY.md) for:
359
+ - Exact minimum-permission SQL scripts for Snowflake and BigQuery
360
+ - Network traffic audit instructions
361
+ - Complete list of what col-reaper reads and what it never reads
362
+
363
+ ---
364
+
365
+ ## Supported warehouses
366
+
367
+ | Warehouse | Status | Query history source | History depth |
368
+ |-----------|--------|---------------------|---------------|
369
+ | Snowflake | ✅ Stable | `ACCOUNT_USAGE.QUERY_HISTORY` (or `INFORMATION_SCHEMA` fallback) | 365 days (7 fallback) |
370
+ | BigQuery | ✅ Stable | `INFORMATION_SCHEMA.JOBS_BY_PROJECT` | 180 days |
371
+ | Redshift | 🔜 Planned | `STL_QUERY` | 7 days |
372
+ | Databricks | 🔜 Planned | `system.access.audit` | 365 days |
373
+ | DuckDB | 🔜 Planned | — | — |
374
+
375
+ ---
376
+
377
+ ## Contributing
378
+
379
+ See [CONTRIBUTING.md](CONTRIBUTING.md) — it includes a step-by-step guide for adding a new warehouse connector.
380
+
381
+ ---
382
+
383
+ ## License
384
+
385
+ MIT © 2026 Sanjay Kandimalla