Skip to main content

bqlens

Find wasted BigQuery spend in one command.

No signup. No sales call. No agent installed in your VPC. It reads your query history, tells you where the money is going, and tells you how to stop it.

pip install bqlens
bqlens scan --project my-project --days 30
  bqlens — my-project
  1,833 query jobs over the last 30 days

  Spend in window      $     1,946.10
  Projected monthly    $     1,946.10
  Recoverable          $       572.50/mo (29% of spend)

  1. [HIGH] Wildcard table scans without _TABLE_SUFFIX  (R004)
     $179.30/mo recoverable   ·  22 jobs
     ...

Try it with no credentials at all:

bqlens scan --demo

What it looks at

bqlens reads INFORMATION_SCHEMA.JOBS_BY_PROJECT — job metadata and the SQL text of your queries.

It never reads a row of your table data. There is no row access, no sampling, no data leaving your project. The whole tool is a read of your own query log plus regex and arithmetic, running on your machine.

What it finds

Rule What it catches Why it costs money
R001 SELECT * on large scans BigQuery bills per column read
R002 LIMIT with no WHERE LIMIT caps rows returned, not bytes scanned
R003 Large scans with no filter No partition pruning
R004 Wildcard tables without _TABLE_SUFFIX Scans every table in the dataset
R005 The same query shape run over and over One materialised refresh replaces all of them
R006 Failed jobs that were still billed Money that bought nothing
R007 Cross joins / joins missing ON Row multiplication

Every dollar is counted once

A repeated SELECT * ... LIMIT matches three rules at once. If each rule counted it, the reported savings would add up to more than your actual bill — and the first thing a sceptical engineer does is add up our numbers.

So rules run in priority order and each job is claimed by exactly one rule, the one with the most specific fix. The sum of findings can never exceed actual spend, and there is a test that fails the build if it ever does.

Savings estimates are deliberately conservative. bqlens counts what a stated fix would plausibly recover, not the full cost of the query. If it says $500, the intent is that you find $500, not that you find $180 and stop trusting it.

Usage

# Basic scan
bqlens scan --project my-project

# Non-US region (the JOBS view is region-qualified)
bqlens scan --project my-project --region region-asia-south1

# Your negotiated rate rather than list price
bqlens scan --project my-project --price-per-tib 5.00

# A page you can forward to your manager
bqlens scan --project my-project --format html --out report.html

# Machine-readable
bqlens scan --project my-project --format json

# Fail CI if waste creeps above a threshold
bqlens scan --project my-project --fail-over 200

Options

Flag Default Meaning
--project — GCP project to scan (required unless --demo)
--region region-us Region of the JOBS view
--days 30 Days of history
--price-per-tib 6.25 On-demand price per TiB scanned
--min-gib 1.0 Ignore queries smaller than this
--min-repeats 10 Repeats before a shape is flagged
--format terminal terminal, json, or html
--out — Write to a file
--fail-over — Exit 1 if monthly recoverable exceeds this
--demo — Run on synthetic data, no credentials

Permissions

The scanning account needs bigquery.jobs.listAll on the project — included in roles/bigquery.resourceAdmin, or grant it directly. Without listAll you will only see your own jobs, not the whole project's.

The metadata query is itself capped at 10 GiB billed, so the scanner can never become the expensive thing in your bill.

Install

pip install bqlens              # CLI + demo mode
pip install 'bqlens[bigquery]'  # adds the BigQuery client for real scans

Python 3.10+. Authenticate with gcloud auth application-default login.

Development

pip install -e '.[dev]'
pytest

Limitations, stated plainly

  • Rules work on query text and job metadata. bqlens does not read table schemas, so it cannot know whether a table is partitioned — R003 flags unfiltered scans as a candidate, not a certainty.
  • Savings percentages per rule are heuristics based on typical wide analytics tables. Your mileage varies.
  • Slot-based (capacity) pricing is not yet modelled; cost figures assume on-demand. Reservation support is planned.
  • SQL parsing is regex-based, not a full parser. Exotic queries may be missed.

Licence

Apache-2.0

Metadata

Release files for bqlens 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bqlens 0.1.0
File Size Uploaded Provenance Actions
bqlens-0.1.0.tar.gz 23.1 kB Without provenance Details for bqlens-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bqlens 0.1.0
File Interpreter ABI Platform Actions
bqlens-0.1.0-py3-none-any.whl Python 3 none any Details for bqlens-0.1.0-py3-none-any.whl

Total release size: 43.8 kB

Release files / bqlens-0.1.0.tar.gz

Download URL bqlens-0.1.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a190571f996043ae6f450b42cc9c013fad9378f7efbb7c6363dcf55121b5e943
BLAKE2b-256 checksum
How to use checksums
0b72a2ddf9a1b5aa0e14f7cf19d8222e7aeb830b62745c99aa942adf8883a936
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / bqlens-0.1.0-py3-none-any.whl

Download URL bqlens-0.1.0-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7fcf576eb341dfc2e4ac62e910128bb283c19c882a69533b5c38c6d58e0e6639
BLAKE2b-256 checksum
How to use checksums
57c8d1c12dee7a6471092e709fcb749f991d1eb7cd4bd3b629163c0b9954de97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for bqlens 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page