Connector
Manages the low-level connection to Google BigQuery.
This class is the core of the connection logic. It is responsible for authenticating, establishing client sessions with both the standard BigQuery API and the BigQuery Storage API, and properly closing them. It is designed to be instantiated and managed by a higher-level class (like a facade) or used directly when manual control over the connection lifecycle is required.
Attributes:
| Name | Type | Description |
|---|---|---|
project_id |
str
|
The GCP project ID for the connection. |
dataset |
str
|
The default dataset to be used. |
credentials |
Optional[Credentials]
|
The authenticated gcloud credentials object after connection. |
client |
Optional[Client]
|
The main BigQuery client. |
bq_storage |
Optional[BigQueryReadClient]
|
The BigQuery Storage API client, used for fast data downloads. |
Example
# Manual Connection Management
from easy_bigquery import BQConnector
# The connector is instantiated but not yet connected.
connector = BQConnector()
try:
# Manually establish the connection.
connector.connect()
print(f'Client is active: {connector.client is not None}')
# Now you can pass this 'connector' instance to a
# Fetcher or Pusher class for operations.
finally:
# Always ensure the connection is closed.
connector.close()
Source code in easy_bigquery/connector/connector.py
__init__(project_id=BQ_PROJECT_ID, credentials_info=BQ_JSON_CREDENTIALS, dataset=BQ_DATASET, table=BQ_TABLE_NAME)
Initializes the BQConnector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
str
|
The GCP project ID. Defaults to the value from the environment configuration. |
BQ_PROJECT_ID
|
credentials_info
|
str
|
A JSON string of the service account credentials. Defaults to the value from the environment configuration. |
BQ_JSON_CREDENTIALS
|
dataset
|
str
|
The default BigQuery dataset name. Defaults to the value from the environment configuration. |
BQ_DATASET
|
table
|
str
|
The default BigQuery table name. Defaults to the value from the environment configuration. |
BQ_TABLE_NAME
|
Source code in easy_bigquery/connector/connector.py
close()
Closes all active BigQuery connections.
Source code in easy_bigquery/connector/connector.py
connect()
Establishes connections to BigQuery clients.