A BigQuery connector for easy data syncing for your custom import. Checks the last date in the table and only appends new data or creates a new table. Made for Google Cloud Functions.
Project description
simple-bigquery-gcf-sync
Created so you only have to focus on the logic for your custom connector. The package takes care of:
- Creating a table if it does not exist
- Getting the latest date in the table if it exists, setting start date to the following day until yesterday
- Conditionally running locally or using a Cloud Function service account
Note:
- Currently defaults to montly table partitioning
- For running locally your project should contain service account
key.jsonin the same folder - You must provide a
default_start_dateandsource_schema
Example usage
# Settings
source_schema = [
bigquery.SchemaField("date", "DATE"),
bigquery.SchemaField("order_id", "STRING"),
bigquery.SchemaField("order_amount", "FLOAT"),
]
default_start_date = "2022-01-01" # Required
def get_data_from_source(start_date, end_date):
# Your custom source logic, should use start and end date
def main(request):
print("⏩ Cloud Function invoked")
project_id = request.args.get("project_id")
dataset_id = request.args.get("dataset_id")
table_id = request.args.get("table_id")
BigQueryConnector.initialize(project_id, dataset_id, table_id)
BigQueryConnector.ensure_table_exists(source_schema)
start_date, end_date = BigQueryConnector.get_date_range(default_start_date)
data = get_data_from_source(start_date, end_date, pub_key, priv_key)
BigQueryConnector.load_data(data)
print("✅ Data processing completed successfully")
return
### For local testing, do not copy into cloud function
if __name__ == "__main__":
class MockRequest:
args = {
"project_id": "project-name",
"dataset_id": "dataset-name",
"table_id": "table-name",
}
main(MockRequest())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple-bigquery-gcf-sync-0.1.0.tar.gz.
File metadata
- Download URL: simple-bigquery-gcf-sync-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
566b196af1bae31e1e19e52c12ff2ff3aa6ad44d2c46aaa5252ecda21c991c78
|
|
| MD5 |
a2f5ae5db3d837e79fdb0940042d057c
|
|
| BLAKE2b-256 |
83249da05f7a603ea05211d6f0e4cf469be454dac672f694280e150838ea6166
|
File details
Details for the file simple_bigquery_gcf_sync-0.1.0-py3-none-any.whl.
File metadata
- Download URL: simple_bigquery_gcf_sync-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71e1008b2af1b0dc1afc0f6ee2bf40a42e1c89da20aa242337175d60309d0d34
|
|
| MD5 |
4b25cf11e07710438ee5ab812d3db359
|
|
| BLAKE2b-256 |
3dd352b9f2e62c8d6b62a05db81d75b3014d9e42237613be599fc337cc8870e2
|