Skip to main content

Nov 19, 2024

How to query a BigQuery table from Python

1. Install the SDK

pyproject.toml
dependencies = [
	"google-cloud-bigquery[bqstorage, pandas]",
]

2. Create a BigQuery client

client.py
from google.cloud import bigquery
 
bq_client = bigquery.Client(project="project")

3. Query your data

query.py
query = """
SELECT column_one, column_two
FROM bq_table
WHERE column_three = true
"""
 
df = bq_client.query(query).to_dataframe()