Skip to main content

A BigQuery Cost Analysis CLI Tool

Project description

QueryGuard CLI 🛡️

The Forensic Auditor for your BigQuery Bill.

Python 3.12+ License: MIT Code Style: Black

QueryGuard (bqg) is a CLI tool that hunts down expensive BigQuery queries across your entire Google Cloud organization. It connects to the INFORMATION_SCHEMA, calculates exact costs based on regional pricing, and flags high-risk patterns like SELECT * or missing LIMIT clauses.

Stop guessing who spent the budget. Know.


⚡ Features

  • 🌍 Global Auto-Discovery: Automatically scans your project to find active regions and queries them in parallel. No more guessing if data is in us-central1 or europe-west3.

  • 💸 Forensic Cost Analysis: Calculates costs based on the exact datacenter pricing (e.g., pricing Zurich queries at $8.75/TiB vs. US queries at $6.25/TiB).

  • 🚩 Risk Detection: Instantly flags bad habits:

    • SELECT * usage
    • Queries without LIMIT
    • Heavy scans (>100 GB)
    • Wrapper scripts vs. actual compute
  • 🤖 Bot Filtering: Use --humans-only to filter out service accounts and Looker bots, focusing strictly on manual engineering errors.

  • 🚀 High Performance: Uses multi-threaded execution to audit dozens of regions in seconds.


📦 Installation

Option 1: Using Pip

pip install queryguard-cli

Option 2: From Source (Poetry)

# Clone the repo
git clone git@github.com:mark-de-haan/query-guard-cli.git

# Navigate
cd queryguard-cli

# Install locally
poetry install

🚀 Quick Start

Ensure you are authenticated with Google Cloud:

gcloud auth application-default login

Run a forensic scan on your primary project for the last 7 days:

bqg scan --project my-gcp-project

Global scanning

Audit every active region globally to find hidden costs:

bqg scan --project my-gcp-project --global

🛠 Usage Guide

The scan Command

Flag Short Description
--project -p Required. The GCP Project ID to audit.
--global -g Auto-discover active regions and scan them all in parallel.
--region -r Scan a specific region (e.g., europe-west1). Ignored if --global is set.
--days -d Lookback window in days (Default: 7).
--humans-only Hides service accounts (e.g., gserviceaccount, monitoring) to find manual errors.
--limit -l Number of expensive queries to display (Default: 10).

Examples

Find who is running expensive queries manually:

bqg scan -p my-data-warehouse --global --humans-only --days 30

Audit a specific region for a deep dive

bqg scan -p my-data-warehouse -r europe-west3

🤝 Contributing

Contributions are welcome! Please check the issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feat/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feat/AmazingFeature)
  5. Open a Pull Request

📄 License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

queryguard_cli-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

queryguard_cli-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file queryguard_cli-0.1.0.tar.gz.

File metadata

  • Download URL: queryguard_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.0 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for queryguard_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3ca9ea0bf921e5702aa3bfdf960818ce20415fcff912bf0ef0e54c6d8f0dfea9
MD5 a9c0f8023465b6f86e23ad2913cb86c7
BLAKE2b-256 e943c86a6c8859fe1085cf59dec3252e1dc8b81722681a0dcda10fb9dc4611f0

See more details on using hashes here.

File details

Details for the file queryguard_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: queryguard_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.0 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for queryguard_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 adcca8166767633cf8bdc4eccfb88de589f3e43a2e058792d423b8be69ae0a38
MD5 b9f17ec46f066ad592afac091f7bdc73
BLAKE2b-256 f0f1e8cf5ec0d2afb009afd7c57e47cf8579b03aa7e92c3212db5b91d58eaff3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page