Metadata-Version: 2.4
Name: bq-inspector
Version: 0.1.0
Summary: Read-only BigQuery job inspection CLI for AI agents
Author: yu-iskw
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10.0
Requires-Dist: click
Requires-Dist: google-auth
Requires-Dist: google-cloud-bigquery
Requires-Dist: jsonschema
Requires-Dist: typing-extensions
Description-Content-Type: text/markdown

# bq-inspector

**bq-inspector** is a read-only CLI for BigQuery: it fetches job metadata (`jobs.get` / `jobs.list`) and dataset or table metadata (`datasets.get`, `tables.list`, `tables.get`). It prints **one JSON document on stdout** on success. Errors are **JSON on stderr** with a non-zero exit code (except plain-text `--help`).

Operational commands take a single **`--params`** JSON object (or `@path` to a file). Field names match the command’s **`--input-schema`** output. For flags and options, **`bq-inspector --help`** and **`bq-inspector <command> --help`** are authoritative; this README may summarize and can lag behind the CLI.

This repository is the **Python** implementation (`pip install bq-inspector`, import name `bq_inspector`). The original **TypeScript** CLI and library live in the [google-cloud-tools](https://github.com/yu-iskw/google-cloud-tools) monorepo under `packages/bq-inspect`. Both implementations target the same agent-facing contracts (command names, `--params` shapes, error codes, and JSON Schema discovery).

## Usage

```bash
bq-inspector <command> --params '<json>' | --params @file.json [options]
```

Every operational command also supports `--input-schema` and `--output-schema` (JSON Schema on stdout, no BigQuery call).

## Install

From PyPI:

```bash
pip install bq-inspector
```

Or install as a standalone tool with [uv](https://github.com/astral-sh/uv):

```bash
uv tool install bq-inspector
```

From source (development or unreleased changes):

```bash
git clone https://github.com/yu-iskw/bq-inspector.git
cd bq-inspector
pip install .
# or: uv sync && uv run bq-inspector --help
```

Requires [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) (ADC) unless you only use schema discovery flags (see below).

## Help

```bash
bq-inspector --help
bq-inspector <command> --help
```

Use `-h` anywhere `--help` is accepted.

Unknown commands print global usage plus `Unknown command: <argv>`.

## Agent workflow

1. Discover the params shape: `bq-inspector <command> --input-schema` (stdout is JSON Schema).
2. Build a JSON object with the required fields (camelCase keys such as `projectId`, `jobId`, `datasetId`).
3. Run the command with inline JSON or a file.

**Pipeline:** `jobs list` → `jobs summary` | `jobs query` | `jobs performance` | `jobs lineage` | `jobs impact` | `jobs get`

**Command forms:** Nested `jobs summary` and flat `summary` are equivalent for job views and `jobs list` → `list`.

**Job id formats:** Pass `jobId` alone, or a Console-style composite id in `jobId`:
`"my-proj:US.bquxjob_abc"` (location is parsed automatically; `projectId` must match if both are set).

**Verifying lineage/impact:** Use a job that references tables. Trivial queries like `SELECT 1` legitimately return empty lineage/impact fields.

**Smoke checklist:** `jobs list` with `allUsers: true` → `jobs summary` and flat `summary` with composite or split job ref.

**Which job command?**

| Goal                                             | Command            |
| ------------------------------------------------ | ------------------ |
| Find job ids (optional client-side filters)      | `jobs list`        |
| Status, timing, bytes/slots (default inspection) | `jobs summary`     |
| SQL, configuration, and light lineage stats      | `jobs query`       |
| Query plan, timeline, performanceInsights        | `jobs performance` |
| Tables, routines, datasets touched               | `jobs lineage`     |
| DML/load/ML/search/export side-effect stats      | `jobs impact`      |
| Full BigQuery Job resource                       | `jobs get`         |

Each view command calls `jobs.get` once per job and projects the response in memory. **`jobs get` returns the full [Job](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job) resource** from the API; other commands slice it for smaller, task-focused JSON. Field names match [Job statistics](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatistics); many nested blocks (for example `statistics.mlStatistics`) appear only for matching job kinds.

**Shared / sandbox projects:** `jobs list` returns your own jobs unless you set `allUsers: true`. In busy sandboxes, list with `allUsers: true`, then pass each job’s `jobReference.location` into job view commands. Omitting `location` on `jobs.get` often returns `BQINSPECTOR_PERMISSION_DENIED` (403), not a clear location error—the CLI hint will suggest adding `location` when that happens.

Example:

```bash
bq-inspector jobs summary --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_JOB_ID"}]}'
bq-inspector summary --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_PROJECT:US.bquxjob_abc"}]}'
```

Optional: `bq-inspector <command> --output-schema` for the response shape.

Invalid params fail with `BQINSPECTOR_INPUT_INVALID` and JSON Schema error paths on stderr; treat `--input-schema` as the contract for `--params`. See [Error codes](#error-codes) for other codes.

## Quickstart

### Inspect jobs

```bash
# Summary (default inspection — no SQL, no query plan)
bq-inspector jobs summary --params "$(cat <<'EOF'
{
  "jobs": [{ "projectId": "YOUR_PROJECT", "jobId": "YOUR_JOB_ID" }]
}
EOF
)"

# Set location from jobs.list jobReference (required for non-default regions)
bq-inspector jobs summary --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_JOB_ID","location":"asia-northeast1"}]}'

# Other job views: include location from jobs.list when jobs are regional (same shape as summary above)
bq-inspector jobs query --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_JOB_ID","location":"asia-northeast1"}]}'
bq-inspector jobs performance --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_JOB_ID","location":"asia-northeast1"}]}'
bq-inspector jobs lineage --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_JOB_ID","location":"asia-northeast1"}]}'
bq-inspector jobs impact --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_JOB_ID","location":"asia-northeast1"}]}'
bq-inspector jobs get --params '{"jobs":[{"projectId":"YOUR_PROJECT","jobId":"YOUR_JOB_ID","location":"asia-northeast1"}]}'
```

### List jobs (`jobs list`)

Field list: [Params reference](#params-reference) (`jobs list`). Full schema: `bq-inspector jobs list --input-schema`.

In shared projects, set `"allUsers": true` or the list may be empty even when jobs exist. Use `jobReference.location` from list output for job view commands.

```bash
bq-inspector jobs list --params "$(cat <<'EOF'
{
  "projectId": "YOUR_PROJECT",
  "allUsers": true,
  "minCreationTime": "2026-05-17T00:00:00Z",
  "maxCreationTime": "2026-05-18T00:00:00Z",
  "minSlotMs": "60000",
  "labels": { "dbt_invocation_id": "abc123" },
  "maxResults": 50
}
EOF
)"
```

### Dataset and table metadata

```bash
bq-inspector datasets get --params '{"projectId":"YOUR_PROJECT","datasetId":"YOUR_DATASET"}'
bq-inspector tables list --params '{"projectId":"YOUR_PROJECT","datasetId":"YOUR_DATASET"}'
bq-inspector tables get --params '{"projectId":"YOUR_PROJECT","datasetId":"YOUR_DATASET","tableId":"YOUR_TABLE"}'
```

## Commands overview

| Command            | What it returns (from help)                          | BigQuery APIs (typical) | Suggested predefined role                                      |
| ------------------ | ---------------------------------------------------- | ----------------------- | -------------------------------------------------------------- |
| `jobs summary`     | Job status, timing, bytes/slots (default inspection) | `jobs.get`              | `roles/bigquery.resourceViewer`                                |
| `jobs query`       | SQL, configuration, light lineage stats              | `jobs.get`              | `roles/bigquery.resourceViewer`                                |
| `jobs performance` | Query plan, timeline, performanceInsights            | `jobs.get`              | `roles/bigquery.resourceViewer`                                |
| `jobs lineage`     | Referenced tables, routines, datasets, destinations  | `jobs.get`              | `roles/bigquery.resourceViewer`                                |
| `jobs impact`      | DML/load/ML/search/export/spark side-effect stats    | `jobs.get`              | `roles/bigquery.resourceViewer`                                |
| `jobs get`         | Full BigQuery Job JSON                               | `jobs.get`              | `roles/bigquery.resourceViewer`                                |
| `jobs list`        | List jobs (optional client-side filters in params)   | `jobs.list`             | `roles/bigquery.resourceViewer`                                |
| `datasets get`     | Dataset metadata                                     | `datasets.get`          | `roles/bigquery.metadataViewer` (often granted on the dataset) |
| `tables list`      | List tables in a dataset                             | `tables.list`           | `roles/bigquery.metadataViewer`                                |
| `tables get`       | Table metadata                                       | `tables.get`            | `roles/bigquery.metadataViewer`                                |

Project-wide `datasets list` is not supported (it would need `datasets.list`, which is outside the usual metadata-only posture).

## Params reference

Summaries from per-command `--help`; full types and constraints: `bq-inspector <command> --input-schema`.

**All commands:** optional `impersonateServiceAccount`, `impersonateDelegates`.

**Job view commands** (`jobs summary`, `jobs query`, `jobs performance`, `jobs lineage`, `jobs impact`, `jobs get`):

- `jobs`: non-empty array of `{ projectId, jobId, location? }` — include `location` from `jobs.list` output when jobs are not in the default region

**`jobs list`:**

- `projectId` (required)
- **Forwarded to `jobs.list` (API):** `minCreationTime`, `maxCreationTime`, `pageToken`, `maxResults`, `allUsers`, `state`, `parentJobId` (`allUsers: true` is often needed in shared sandboxes)
- **Post-list (current page only):** `minSlotMs`, `minBytesBilled`, `labels` — paginate with `pageToken` if you need more matches. The Python port matches labels under `configuration.labels` (typical BigQuery shape); the TypeScript port only checks top-level `labels`.
- Regional jobs: read `jobReference.location` from list output; pass `location` on job view commands, not on `jobs list` (BigQuery does not support a location query param on `jobs.list`)

**Catalog** (`datasets get`, `tables list`, `tables get`):

- `projectId`, `datasetId` (`tableId` required for `tables get`)
- `tables list` returns all tables in the dataset (the SDK auto-paginates `tables.list`). Unlike `jobs list`, there is no `pageToken` on this command.

## JSON Schema discovery

- **Discovery:** `--input-schema` or `--output-schema` (use one at a time; prints JSON Schema on stdout and exits without calling BigQuery).
- **Required for runs:** `--params` as JSON or `@path` to a JSON file.

Examples:

```bash
bq-inspector jobs summary --input-schema
bq-inspector jobs summary --output-schema
bq-inspector jobs get --input-schema
bq-inspector jobs list --input-schema
bq-inspector datasets get --output-schema
```

## Error codes

Errors are JSON on stderr with a `code` field. Schema validation failures include `schemaErrors` with JSON Pointer paths.

| Code                            | Typical cause                                                                                                   |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `BQINSPECTOR_INPUT_INVALID`     | Bad `--params` or flags; schema validation; HTTP 4xx (except 401/403/404/429).                                  |
| `BQINSPECTOR_PERMISSION_DENIED` | IAM or ADC; on `jobs.get`, often missing `location` or wrong job ref (see [Troubleshooting](#troubleshooting)). |
| `BQINSPECTOR_JOB_NOT_FOUND`     | HTTP 404 from BigQuery (job or catalog). Read `source.api` and `hint` for the resource type.                    |
| `BQINSPECTOR_LOCATION_REQUIRED` | Reserved; prefer `location` on job refs (see hints on 403).                                                     |
| `BQINSPECTOR_API_RATE_LIMITED`  | HTTP 429; retryable.                                                                                            |
| `BQINSPECTOR_API_UNAVAILABLE`   | Transient API / 5xx.                                                                                            |
| `BQINSPECTOR_INTERNAL`          | Unexpected CLI failure.                                                                                         |

## Troubleshooting

Symptom-first checks when JSON looks wrong but the CLI is working:

**`jobs list` returns `"jobs": []`**

- In shared sandboxes, set `"allUsers": true` in `--params` (default list is only your user’s jobs).
- With impersonation: the caller needs **Service Account Token Creator** on the target; the impersonated identity needs **BigQuery job list** access (`roles/bigquery.resourceViewer` or equivalent).

**Job view commands return per-job `BQINSPECTOR_PERMISSION_DENIED` (403)**

- **`location` omitted:** copy `jobReference.location` from `jobs list` into each job ref (required for many regional jobs).
- **`location` set:** BigQuery may still return **403 Access Denied** for a wrong `jobId`, wrong region, or IAM—not only missing `location`. Confirm `projectId` and `jobId` from `jobs list`; do not assume the code will be `BQINSPECTOR_JOB_NOT_FOUND`.

**`BQINSPECTOR_JOB_NOT_FOUND`**

- Typical for a wrong **project** on a job ref, a missing **dataset** or **table**, or catalog APIs returning HTTP 404.
- The error code matches the TypeScript port for all 404 responses. Use **`source.api`** (`bigquery.jobs.get` vs `bigquery.datasets.get`, etc.) and the stderr **`hint`** to tell jobs from catalog resources apart.

**Post-filters on `jobs list`** (`minSlotMs`, `minBytesBilled`, `labels`)

- Applied to the **current API page only**. If results are empty, increase `maxResults` or follow `pageToken` until matches appear.

**Multi-job `--params`**

- The process can exit **0** while individual entries in `jobs[]` include `errors`. Inspect each job element.

## Authentication

The CLI uses the official **BigQuery** client with **Application Default Credentials** from `google-auth`.

- **Default:** credentials are scoped to `https://www.googleapis.com/auth/bigquery.readonly`.
- **Impersonation:** set `impersonateServiceAccount` (and optional `impersonateDelegates`) in `--params`. The source principal must have **Service Account Token Creator** on the target (and on each delegate). While impersonating, access is still requested with `bigquery.readonly` on the **target** identity. The source ADC client uses `https://www.googleapis.com/auth/cloud-platform` only for the token exchange path.

Example params fragment:

```json
{
  "impersonateServiceAccount": "TARGET@PROJECT_ID.iam.gserviceaccount.com",
  "impersonateDelegates": ["FIRST_DELEGATE@PROJECT_ID.iam.gserviceaccount.com"]
}
```

Service account **JSON key files** are not a dedicated CLI option; ADC may still resolve a key via environment if your platform configures it that way.

## IAM guidance

Prefer narrow read access:

- **Job commands / `jobs list`:** `roles/bigquery.resourceViewer` (or a custom role with `bigquery.jobs.get` / `bigquery.jobs.list`) on the **identity that calls BigQuery** (the impersonated service account when using impersonation).
- **`datasets get` / `tables list` / `tables get`:** `roles/bigquery.metadataViewer` on the dataset or project (or a custom metadata-only role with `datasets.get`, `tables.list`, `tables.get`).
- Grant the calling principal `roles/iam.serviceAccountTokenCreator` on the target service account (and delegates, if any) when using impersonation.
- Avoid `roles/bigquery.dataViewer` and `roles/bigquery.jobUser` for inspection-only workflows.

## Programmatic use (Python)

The primary surface is the **`bq-inspector` CLI**. For in-process use, import from the `bq_inspector` package (for example core use cases under `bq_inspector.core`, ports under `bq_inspector.bigquery.port`, and JSON Schema helpers under `bq_inspector.schemas`). The package does not yet expose a stable public API beyond what the CLI uses internally; prefer subprocess invocation or the TypeScript library in [google-cloud-tools](https://github.com/yu-iskw/google-cloud-tools/tree/main/packages/bq-inspect) if you need a documented library entrypoint today.

See [CONTRIBUTING.md](CONTRIBUTING.md) for architecture and test patterns when extending the Python implementation.

## Security notes

**Read-only metadata:** job resources and dataset/table metadata only. No table row reads and no arbitrary query execution. Job output may include SQL, user emails, and other fields from the BigQuery API; the caller is responsible for where JSON is stored or logged.

## Development

See [CONTRIBUTING.md](CONTRIBUTING.md) and [AGENTS.md](AGENTS.md) for setup, lint, and test commands.

```bash
make setup
make lint
make test
```
