Google BigQuery Python client · query · load · to_dataframe · cost control · verified against google-cloud-bigquery 3.x (2026)

BigQuery Python cheat sheet

google-cloud-bigquery is the official client for Google's serverless data warehouse. Make a Client, run SQL with client.query(), and pull results into a pandas DataFrame with .to_dataframe(). Load DataFrames & files back with load_table_from_dataframe() / load_table_from_uri(). Because BigQuery bills by bytes scanned, this sheet leans hard on parameterized queries, dry runs, and cost controls. Targets google-cloud-bigquery 3.x, Python 3.10+.

connect & query dataframes datasets & tables jobs & cost performance & ecosystem gotcha / cost most common

Verified 2026-08-31 against the Google Cloud docs (google-cloud-bigquery 3.44.0, released 2026-08-24; Python 3.10–3.14). Table refs are project.dataset.table. Auth uses Application Default Credentials (gcloud auth application-default login or a service-account key).

Outline

Client, then query(). Pull results to DataFrames, load data back, manage datasets/tables, and — always — control what you scan.

Connect & query

  1. 1Install & Client
  2. 2Run a query
  3. 3Query parameters

DataFrames

  1. 4Query → DataFrame
  2. 5Load DataFrame → table

Datasets & tables

  1. 6Datasets & tables
  2. 7Load from files / GCS
  3. 8Schema

Jobs, cost & ecosystem

  1. 9Dry run & cost control
  2. 10Streaming & write API
  3. 11Performance & ecosystem

Connect & Query

Authenticate once, then run SQL and read results — safely, with parameters.

1Install & Clientauth
2Run a query.query()
3Query parameterssafe SQL

DataFrames

The pandas bridge in both directions — the most common analytics workflow.

4Query → DataFrameread
5Load DataFrame → tablewrite

Datasets & Tables

Create and manage datasets/tables; load from files and GCS.

6Datasets & tablesDDL via API
7Load from files / GCSingest
8Schemafield types

Jobs & Cost

BigQuery bills by bytes scanned — measure before you run, and cap spend.

9Dry run & cost controlbytes = money
10Streaming & write APIreal-time in

Performance & Ecosystem

Faster reads and the higher-level tools around the client.

11Performance & ecosystemthe wider stack

Worth memorizing

bigquery.Client(project=)project = billing; set location=
client.query(sql).result()QueryJob -> RowIterator
query_and_wait(sql)newer run+wait one-liner
.to_dataframe()+ create_bqstorage_client=True for speed
@param + QueryJobConfigparameterize — never f-string SQL
load_table_from_dataframewrite_disposition WRITE_TRUNCATE/APPEND
load_table_from_urigs:// CSV/JSON/PARQUET/AVRO
SchemaField(name, type, mode)REPEATED = array, RECORD = struct
dry_run=Trueestimate bytes, $0 to run
maximum_bytes_billedhard cost cap
avoid SELECT *bills by columns scanned; filter partitions
bigquery-storagefast parallel reads