🧹 BigQuery Cleaner
BigQuery Cleaner is a powerful CLI tool designed to help you declutter your Google BigQuery environment. It identifies tables that haven't been queried recently and provides safe mechanisms to rename or prepare them for deletion.
🚀 Quick Start
Get up and running in seconds:
# 1. Install via uv (recommended)
uv tool install bigquery-cleaner
# Or via pip
pip install bigquery-cleaner
# 2. Find unused tables (older than 30 days and not queried)
bigquery-cleaner list-unused-tables --project your-gcp-project --all-datasets --days 30
✨ Features
- 🔍 Unused Table Detection: Scans
INFORMATION_SCHEMA.JOBSto find tables that aren't being used. - 🌐 Cross-Project Jobs History: Optionally scans
INFORMATION_SCHEMA.JOBSin extra projects withjobs_projectsor--jobs-projects. - 📊 Storage Insight: Displays table sizes in GB and provides per-dataset and grand total summaries.
- 📂 Multi-Dataset Support: Target specific datasets, exclude others, or scan your entire project.
- 🏷️ Safe Renaming: Dry-run mode allows you to see what would happen before making changes.
- 🔄 Easy Revert: Renamed a table by mistake? Revert it easily with the
revert-renamed-tablescommand. - 🗑️ Permanent Cleanup: Use
delete-tablesto remove suffixed tables once you've confirmed they are no longer needed. - 🧹 Dataset Cleanup: Remove empty datasets that no longer contain any tables or views using
delete-empty-datasets. - ⚙️ Configurable: Use a
cleaner.tomlfile to save your project defaults and lookback windows. - ⚡ Built with Speed: Powered by
uv,Typer, andRichfor a fast terminal experience.
📋 Prerequisites
- Python 3.10+
- uv package manager installed.
- Google Cloud Credentials: Configured via Application Default Credentials (ADC).
gcloud auth application-default login
🛠️ Installation
Using uv (Recommended)
uv tool install bigquery-cleaner
Using pip
pip install bigquery-cleaner
From Source (Development)
# Clone the repository
git clone https://github.com/elvainch/bigquery-cleaner.git
cd bigquery-cleaner
# Sync dependencies and install the tool
uv sync
uv tool install .
📖 Usage Guide
Help Command
Every command and sub-command supports the
--helpflag for detailed information on available options.Example:
bigquery-cleaner list-unused-tables --helpRun
bigquery-cleaner --helpto see all available commands.
Connectivity Check
Ensure your credentials and project access are working:
bigquery-cleaner ping --project YOUR_PROJECT
Exploration
List available datasets and tables:
# List all datasets
bigquery-cleaner datasets --project YOUR_PROJECT
# List tables in specific datasets
bigquery-cleaner tables --datasets dataset1,dataset2 --project YOUR_PROJECT
Identifying Waste
The core functionality to find old, unreferenced tables:
# List unused tables across all datasets
bigquery-cleaner list-unused-tables --project YOUR_PROJECT --all-datasets --days 90
Cleanup Operations
Safely rename unused tables with a suffix:
# Dry run first!
bigquery-cleaner rename-old-tables --project YOUR_PROJECT --all-datasets --days 90 --dry-run
# Perform the rename
bigquery-cleaner rename-old-tables --project YOUR_PROJECT --all-datasets --days 90
# Revert a previous rename
bigquery-cleaner revert-renamed-tables --project YOUR_PROJECT --all-datasets --suffix "_renamed_20260902"
# Delete renamed tables after verification
# Dry run first!
bigquery-cleaner delete-tables --project YOUR_PROJECT --all-datasets --suffix "_renamed_20260902" --dry-run
# Perform the deletion
bigquery-cleaner delete-tables --project YOUR_PROJECT --all-datasets --suffix "_renamed_20260902"
# Remove empty datasets
bigquery-cleaner delete-empty-datasets --project YOUR_PROJECT --all-datasets
⚙️ Configuration
Tired of typing the same flags? Create a cleaner.toml file in your project root. All CLI options can be persisted here:
[bigquery_cleaner]
# GCP Project ID (required; the CLI does not fall back to the ADC default project)
project = "your-gcp-project"
# List of datasets to scan (dataset names only; do not use project.dataset)
datasets = ["dataset1", "dataset2"]
# List of datasets to ignore
exclude_datasets = ["logs_dataset", "temp_staging"]
# Extra projects whose INFORMATION_SCHEMA.JOBS history should count as usage.
# The main project is always included automatically.
jobs_projects = ["analytics-project", "bi-project"]
# If true, scans all datasets in the project (used only when 'datasets' is omitted or empty)
all_datasets = true
# Lookback window in days for identifying unused tables (default: 30)
days = 60
# Suffix used for renaming and identifying tables for deletion (default: _renamed_YYYYMMDD)
rename_suffix = "_old_backup"
# Default behavior for mutation commands (true = dry run by default)
dry_run = false
# Logging level (DEBUG, INFO, WARNING, ERROR)
log_level = "INFO"
Then run with:
bigquery-cleaner list-unused-tables --config cleaner.toml
📝 Notes
- Explicit Project Required: Pass
--projector setprojectincleaner.toml. ADC authentication is used, but ADC default-project fallback is disabled. - Dataset Names:
datasetsandexclude_datasetsmust be unqualified dataset names such asanalytics, notmy-project.analytics. - Detection Logic: The
list-unused-tablescommand identifies tables whosestorage_last_modified_timeis older thanNdays and that do not appear inINFORMATION_SCHEMA.JOBS.referenced_tableswithin that same window. - Cross-Project Usage Checks: Set
jobs_projectsor pass--jobs-projectsto also scan query history from other projects that may read the same tables. - Config Precedence: CLI flags override
cleaner.toml. If bothall_datasetsanddatasetsare set, the explicitdatasetslist is used. - Long-Running Commands:
list-unused-tables,rename-old-tables,revert-renamed-tables, anddelete-tablesprint a repeated analysis status message while building the work plan. Mutation commands then switch to a live progress bar during execution. - Rich Output: All results are displayed in terminal tables thanks to
Rich, including total table counts and storage size summaries. - Linting & Quality: The project uses Ruff for fast linting and formatting.
Check out the project on:
- PyPI: https://pypi.org/project/bigquery-cleaner/
- GitHub: https://github.com/elvainch/bigquery-cleaner
Developed by Alan Vainsencher.
Metadata
Release files for bigquery-cleaner 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bigquery_cleaner-0.1.10.tar.gz | 73.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bigquery_cleaner-0.1.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 95.4 kB
Release files / bigquery_cleaner-0.1.10.tar.gz
| Download URL | bigquery_cleaner-0.1.10.tar.gz |
|---|---|
| Size | 73.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
643a2482b3627ea0c88606cd2e39ee96de84daf677289a5ff0c23d167bcab224
|
|
BLAKE2b-256 checksum How to use checksums |
c341ffe96a815946a80a0f433a181adc919e522b5796a24fa6bac36c577cfe4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.25
|
Release files / bigquery_cleaner-0.1.10-py3-none-any.whl
| Download URL | bigquery_cleaner-0.1.10-py3-none-any.whl |
|---|---|
| Size | 22.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2206598c4024ef682f2ae7e79b90e5b289898ff4772e1dd70cea1d93f0d62fff
|
|
BLAKE2b-256 checksum How to use checksums |
1495494c3e9effbd676d3cfae18889c39da224279e78b202d12ddd50c85fac3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.25
|
Security for bigquery-cleaner 0.1.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.