BigQuery

Query BigQuery from deployed models with zero-key authentication and write forecasts back with native bulk loads.

rb.sources.bigquery connects deployed Rebase code to BigQuery. It shares the uniform data-source surface: read, read_bitemporal, and write.

Install

uv pip install "rebase-toolkit[bigquery]"

Ships google-cloud-bigquery[pandas] and db-dtypes. Declare it on the image you deploy:

image = rb.Image.python("3.12").uv_pip_install("rebase-toolkit[bigquery]")

Authenticate

BigQuery is the one warehouse with a zero-configuration path: Application Default Credentials. If your deployed code runs with a service account that has BigQuery access, rb.sources.bigquery() works with no settings at all.

To query a different project, or from outside Google Cloud, use a service-account key:

rebase secret create acme-bigquery \
    BIGQUERY_PROJECT=acme-analytics \
    GOOGLE_APPLICATION_CREDENTIALS=/secrets/sa.json

Prefer keyless: grant the deploy's runtime service account roles/bigquery.dataViewer (+ dataEditor for writes and jobUser to run queries) on the target project and skip key files entirely.

Settings

SettingEnvironment variableRequired
projectBIGQUERY_PROJECT / GOOGLE_CLOUD_PROJECT / GCLOUD_PROJECToptional
locationBIGQUERY_LOCATIONoptional
credentials_pathGOOGLE_APPLICATION_CREDENTIALSoptional

Any setting can also be passed to the factory directly, or namespaced per connection as REBASE_SOURCE_<CONNECTION>_<FIELD> — see credential precedence.

Read

Parameters are a dict, bound as named @param query parameters (BigQuery's typed binding — no string interpolation):

import rebase as rb

src = rb.sources.bigquery(connection="acme")
df = src.read(
    "SELECT ts, issued_at, load_mw FROM `acme.energy.demand` WHERE site = @site",
    params={"site": "site-001"},
)

For backtesting, declare knowledge time so emflow can prove there is no leakage:

from rebase.sources import BitemporalSpec

spec = BitemporalSpec(valid_time="ts", knowledge_time="issued_at")
df = src.read_bitemporal(
    "SELECT ts, issued_at, load_mw FROM `acme.energy.demand`",
    spec,
)

Write forecasts back

Writes use BigQuery's native load path (load_table_from_dataframe); mode="replace" maps to WRITE_TRUNCATE:

src.write(forecast_df, "acme.energy.forecasts", mode="append")

Reference

On this page