Skip to content

BigQuery

Installation

pip install "toolfront[bigquery]"

Connection URL

Connect to BigQuery by passing a connection URL to the Database constructor:

1
2
3
4
5
from toolfront import Database

db = Database(url="bigquery://{project_id}/{dataset_id}")

revenue = db.ask("What's our total revenue this month?")

Connection Parameters

Alternatively, connect using the Database.from_bigquery() method with parameters:

1
2
3
4
5
6
7
8
9
from toolfront import Database

db = Database.from_bigquery(
    project_id="my-project",
    dataset_id="sales",
    location="us-west1"
)

revenue = db.ask("What's our total revenue this month?")
PARAMETER DESCRIPTION
project_id

A BigQuery project id.

TYPE: str DEFAULT: None

dataset_id

A dataset id that lives inside of the project indicated by project_id. Default is ''.

TYPE: str DEFAULT: ''

credentials

Optional credentials.

TYPE: Credentials DEFAULT: None

application_name

A string identifying your application to Google API endpoints.

TYPE: str DEFAULT: None

auth_local_webserver

Use a local webserver for the user authentication. Binds a webserver to an open port on localhost between 8080 and 8089, inclusive, to receive authentication token. If not set, defaults to False, which requests a token via the console. Default is True.

TYPE: bool DEFAULT: True

auth_external_data

Authenticate using additional scopes required to query external data sources, such as Google Sheets, files in Google Cloud Storage, or files in Google Drive. If not set, defaults to False, which requests the default BigQuery scopes. Default is False.

TYPE: bool DEFAULT: False

auth_cache

Selects the behavior of the credentials cache. 'default' - Reads credentials from disk if available, otherwise authenticates and caches credentials to disk. 'reauth' - Authenticates and caches credentials to disk. 'none' - Authenticates and does not cache credentials. Default is 'default'.

TYPE: str DEFAULT: 'default'

partition_column

Identifier to use instead of default _PARTITIONTIME partition column. Default is 'PARTITIONTIME'.

TYPE: str DEFAULT: 'PARTITIONTIME'

client

A Client from the google.cloud.bigquery package. If not set, one is created using the project_id and credentials.

TYPE: Client DEFAULT: None

storage_client

A BigQueryReadClient from the google.cloud.bigquery_storage_v1 package. If not set, one is created using the project_id and credentials.

TYPE: BigQueryReadClient DEFAULT: None

location

Default location for BigQuery objects.

TYPE: str DEFAULT: None

generate_job_id_prefix

Optional callable that generates a bigquery job ID prefix. If specified, for any query job, jobs will always be created rather than optionally created by BigQuery's Client.query_and_wait.

TYPE: Callable[[], str | None] DEFAULT: None

match_schema

Regex pattern to filter schemas. Mutually exclusive with match_tables.

TYPE: str DEFAULT: None

match_tables

Regex pattern to filter tables. Mutually exclusive with match_schema.

TYPE: str DEFAULT: None

**kwargs

Additional arguments passed to the DBAPI connection call.

TYPE: Any DEFAULT: {}