Skip to main content

GCP Utility tool

We can backfill any kind of bigquery sql to specific destination table with powerful python jinja templating feature. By default it can support date templates in your query. It will automatically convert to date template to date value in your query while executing.

Following are the available date templates you can use it in your query.

{{ds}} - YYYY-DD-MM date string 
{{ds_nodash}} - YYYYDDMM date string 
{{ds_yesterday}} - YYYY-DD-MM yesterday date string 
{{ds_yesterday_nodash}} - YYYYDDMM yesterday date string 
{{ds_tomorrow}} - YYYY-DD-MM tomorrow date string 
{{ds_tomorrow_nodash}} - YYYYDDMM tomorrow date string 

Getting Started

Installing

Use virtualenv to Install the dependancy packages

pip install virtualenv
virtualenv venv
. ./venv/bin/activate
##### Windows:
python -m pip install virtualenv
python -m virtualenv venv
./venv/Scripts/activate

Install bq_client command line tool using pip

pip install gcp-utility

-h command will return the help content which contains all the available options

bq_client -h

End with an example of getting some data out of the system or using it for a little demo

Available option

usage: bq_client.py [-h] [-q QUERY] [-f] [-p PROJECT] [-ssql] [-dml]
                    [-d DESTINATION_TABLE] [-w WRITE_DESPOSITION]
                    [-qf QUERY_FILE] [-t TEMPLATE] [-tf TEMPLATE_FILE]
                    [-s START_DATE] [-e END_DATE] [-sf SERVICE_ACCOUNT_PATH]

optional arguments:
  -h, --help            show this help message and exit
  -q QUERY, --query QUERY
                        provide valid bigquery sql
  -f, --no-flattern     Flattern results
  -p PROJECT, --project_id PROJECT
                        provide valid project id
  -ssql, --standard-sql
                        Mention if using Standard sql
  -dml, --dml-statement
                        Mention if using DML statements in your query
  -d DESTINATION_TABLE, --destination-table DESTINATION_TABLE
                        <projectname>:<datasetid>.<tableid> provide valid
                        destination project-id
  -w WRITE_DESPOSITION, --write-desposition WRITE_DESPOSITION
                        Write disposition value
  -qf QUERY_FILE, --query-file QUERY_FILE
                        provide bigquery sql filepath
  -t TEMPLATE, --template TEMPLATE
                        provide template values
  -tf TEMPLATE_FILE, --template-file TEMPLATE_FILE
                        provide template file path
  -s START_DATE, --start-date START_DATE
                        Provide valid startdate (YYYY-MM-DD)
  -e END_DATE, --end-date END_DATE
                        Provide valid end date (YYYY-MM-DD)
  -sf SERVICE_ACCOUNT_PATH, --service-account-file-path SERVICE_ACCOUNT_PATH
                        provide valid path of service account json file

passing raw query

you can pass the raw query to script that need to be execute

bq_client -q "select * from [sample_proj:datasetid.tableid]" -p destination_projectid -d dest_datasetid.tableid

Using sql file

if your query is quite long, you can save it to text file and pass the path of it

bq_client --query-file "/path/sample.sql" -p destination_projectid -d dest_datasetid.tableid```

Passing date parameter

In default it will substitute current date into template fields. but if you want to change the date value you can pass manually using start date parameter

bq_client --query-file sample.sql -p projectid -d dest_datasetid.tableid -s 2018-02-02

Backfill

Pass start-date and end-date to script, it will backfill the data.

bq_client --query-file sample.sql -p projectid -d dest_datasetid.tableid -s 2018-02-02 -e 2018-02-10

Development

What things you need to install the software and how to install them

google-cloud-bigquery==1.24.0
Jinja2==2.11.2

Metadata

Release files for gcp-utility 2.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for gcp-utility 2.0.5
File Interpreter ABI Platform
gcp_utility-2.0.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / gcp_utility-2.0.5-py2.py3-none-any.whl

Download URL gcp_utility-2.0.5-py2.py3-none-any.whl
Size 8.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dd1eaa4b63b0df9631c09b4f4ff4bb0d17083183a8ea40d616bde9869fdb9ec5
BLAKE2b-256 checksum
How to use checksums
c986fbb5a18b2c3304ff42940ede7cefa2da36adab8befa76db9c8084c1c9160
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.8

Security for gcp-utility 2.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page