Google Cloud BigQuery
raw JSON → 3.40.1 verified Tue May 12 auth: no python install: verified quickstart: stale
Official Python client for Google BigQuery. Current version: 3.40.1 (Mar 2026). v3.0 made google-cloud-bigquery-storage and pyarrow required dependencies. Authentication uses Application Default Credentials (ADC) — no explicit API key. query() returns a QueryJob — must call .result() to wait for completion. to_dataframe() dtype behavior changed in v3 (nullable pandas dtypes). Python 3.9+ required as of v3.x.
pip install google-cloud-bigquery Common errors
error ModuleNotFoundError: No module named 'google.cloud.bigquery' ↓
cause The `google-cloud-bigquery` Python package is not installed in the active environment or is not accessible on the Python path.
fix
Ensure the package is installed using pip:
pip install google-cloud-bigquery error google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. ↓
cause The client library could not find valid Google Cloud credentials in the environment. This typically means Application Default Credentials (ADC) are not set up.
fix
Authenticate by running
gcloud auth application-default login in your terminal, or by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of a service account key JSON file. error google.api_core.exceptions.BadRequest: 400 GET ... Invalid project ID '`your-project-id`'. ↓
cause The specified Google Cloud project ID is incorrect, misspelled, or the authenticated principal lacks permissions to access it.
fix
Verify that the
project argument in bigquery.Client(project='your-project-id') is exactly the correct Google Cloud Project ID, and ensure your authenticated account or service account has the necessary BigQuery permissions for that project. error AttributeError: 'QueryJob' object has no attribute 'to_dataframe' ↓
cause The `to_dataframe()` method is called directly on the `QueryJob` object. The `to_dataframe()` method is available on the `QueryJob.result()` object (which is a `RowIterator`), and requires `google-cloud-bigquery-storage` and `pyarrow` to be installed.
fix
Call
.result() on the QueryJob first to get the results iterator, then call .to_dataframe() on that iterator. Also, ensure google-cloud-bigquery-storage and pyarrow are installed: pip install google-cloud-bigquery-storage pyarrow.
client = bigquery.Client()
query_job = client.query("SELECT 1")
df = query_job.result().to_dataframe() Warnings
breaking google-cloud-bigquery-storage and pyarrow are now required dependencies in v3.x (previously optional). Installing v3 without them causes ImportError on to_dataframe(). ↓
fix pip install 'google-cloud-bigquery[pandas]' — installs all required deps including db-dtypes.
breaking to_dataframe() dtype mappings changed in v3. INT64 → Int64 (nullable), BOOLEAN → boolean (nullable), DATE → dbdate. Code checking dtype == 'int64' or 'bool' will fail silently or raise. ↓
fix Use pandas nullable dtypes in comparisons: df['col'].dtype == 'Int64' not 'int64'. Or use pd.api.types.is_integer_dtype().
gotcha client.query() returns a QueryJob — NOT results. It starts the job asynchronously. Must call .result() to block and wait for completion before iterating rows. ↓
fix rows = client.query(sql).result() — the .result() call is mandatory.
gotcha Authentication uses Application Default Credentials (ADC) — no API key. Locally: run 'gcloud auth application-default login'. In production: use service account key or Workload Identity. Missing credentials raises DefaultCredentialsError. ↓
fix Local: gcloud auth application-default login. Production: set GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json or use Workload Identity.
gotcha BigQuery table references use backtick syntax in SQL: `project.dataset.table`. Using regular quotes raises BadRequest syntax error. ↓
fix SELECT * FROM `myproject.mydataset.mytable` — backticks required for fully qualified table names.
gotcha StandardSqlDataType and related types moved from google.cloud.bigquery_v2 to google.cloud.bigquery in v3. Old imports raise ImportError. ↓
fix from google.cloud.bigquery import StandardSqlDataType — not from google.cloud.bigquery_v2
gotcha Python 3.7 and 3.8 support dropped in v3.x. New major version in Q4 2024 dropped these Python versions. ↓
fix Use Python 3.9+
Install
pip install 'google-cloud-bigquery[pandas]' pip install 'google-cloud-bigquery[pandas,pyarrow]' Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) pandas,pyarrow - - 2.58s 390.1M
3.10 alpine (musl) pandas - - 2.60s 390.1M
3.10 alpine (musl) google-cloud-bigquery - - 1.28s 71.2M
3.10 slim (glibc) pandas,pyarrow - - 1.77s 357M
3.10 slim (glibc) pandas - - 1.79s 357M
3.10 slim (glibc) google-cloud-bigquery - - 0.86s 69M
3.11 alpine (musl) pandas,pyarrow - - 3.81s 417.3M
3.11 alpine (musl) pandas - - 3.83s 417.3M
3.11 alpine (musl) google-cloud-bigquery - - 2.18s 76.3M
3.11 slim (glibc) pandas,pyarrow - - 2.79s 383M
3.11 slim (glibc) pandas - - 2.79s 383M
3.11 slim (glibc) google-cloud-bigquery - - 1.42s 74M
3.12 alpine (musl) pandas,pyarrow - - 3.75s 410.1M
3.12 alpine (musl) pandas - - 3.82s 410.1M
3.12 alpine (musl) google-cloud-bigquery - - 2.06s 67.6M
3.12 slim (glibc) pandas,pyarrow - - 3.41s 376M
3.12 slim (glibc) pandas - - 3.42s 376M
3.12 slim (glibc) google-cloud-bigquery - - 1.72s 65M
3.13 alpine (musl) pandas,pyarrow - - 3.59s 409.1M
3.13 alpine (musl) pandas - - 3.64s 409.1M
3.13 alpine (musl) google-cloud-bigquery - - 2.06s 67.2M
3.13 slim (glibc) pandas,pyarrow - - 3.35s 375M
3.13 slim (glibc) pandas - - 3.27s 375M
3.13 slim (glibc) google-cloud-bigquery - - 1.72s 65M
3.9 alpine (musl) pandas,pyarrow - - 2.38s 385.0M
3.9 alpine (musl) pandas - - 2.39s 385.0M
3.9 alpine (musl) google-cloud-bigquery - - 1.24s 71.3M
3.9 slim (glibc) pandas,pyarrow - - 2.12s 359M
3.9 slim (glibc) pandas - - 2.08s 359M
3.9 slim (glibc) google-cloud-bigquery - - 1.02s 69M
Imports
- Client (basic query) wrong
from google.cloud import bigquery client = bigquery.Client() # Wrong: using query result directly without .result() rows = client.query('SELECT 1') # returns QueryJob not rows for row in rows: # iterates before job completes print(row)correctfrom google.cloud import bigquery # ADC auth — uses GOOGLE_APPLICATION_CREDENTIALS env var # or gcloud CLI credentials locally client = bigquery.Client(project='my-project') # query() returns a QueryJob — NOT results query = """ SELECT name, COUNT(*) as count FROM `bigquery-public-data.usa_names.usa_1910_2013` WHERE state = 'TX' GROUP BY name ORDER BY count DESC LIMIT 10 """ query_job = client.query(query) # starts job rows = query_job.result() # BLOCKS until complete for row in rows: print(row.name, row.count) - to_dataframe wrong
# Expecting non-nullable pandas dtypes from to_dataframe df = client.query('SELECT count FROM table').result().to_dataframe() assert df['count'].dtype == 'int64' # fails in v3 — now Int64 (nullable)correctfrom google.cloud import bigquery client = bigquery.Client(project='my-project') query = 'SELECT id, name, created_at FROM `myproject.mydataset.mytable` LIMIT 100' # to_dataframe() requires pandas + pyarrow + db-dtypes df = client.query(query).result().to_dataframe() print(df.dtypes) # id: Int64 (nullable) — not int64 # name: object # created_at: dbdate
Quickstart stale last tested: 2026-04-23
# pip install 'google-cloud-bigquery[pandas]'
# Set up ADC: gcloud auth application-default login
# or set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
from google.cloud import bigquery
client = bigquery.Client(project='my-gcp-project')
# Query public dataset
query = """
SELECT
name,
SUM(number) as total
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE state = 'CA'
GROUP BY name
ORDER BY total DESC
LIMIT 5
"""
# Run query and wait for results
query_job = client.query(query)
rows = query_job.result() # blocks until done
for row in rows:
print(f'{row.name}: {row.total}')
# As DataFrame
df = rows.to_dataframe()
print(df.head())