Notes from BenDesk: Connecting PAD to Python

Ben is our resident ZenDesk captain and manager of all help@ inquiries. We’re bringing you interesting inquiries from his inbox each month to help share learnings across our community.

Question of the Month: Is it possible to connect PAD to Python? If so, how do I set this up and authenticate access?

Bendesk Answer: Yes, there is! A lot of people prefer using Python for data manipulation and interaction. BigQuery provides a variety of ways to effortlessly connect to your data using Python, including Google Colab (similar to Jupyter Notebook), Cloud Shell, and Google Cloud CLI. You can also use the Python client library and the Google Cloud CLI to connect to PAD from your local environment.

To get started, first install the Google Cloud CLI. Next, add gcloud CLI to your PATH by running the install.sh script. Once installed, follow the instructions on the page to initialize gcloud CLI and grant your computer access to your PAD project. It’s important to remember to log in and grant access using your CTA Google account instead of any personal or work emails.

Afterward, you can install the Python client library named “google-cloud-bigquery,” which you can use in your Python scripts. The library will automatically use your default gcloud configuration set up using the gcloud CLI. Once it’s successfully installed and authenticated, you can test if it works correctly by running the sample code below:

> from google.cloud import bigquery > > client = bigquery.Client() > > QUERY = ( > > ‘SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` ‘ > > ‘WHERE state = “TX” ‘ > > ‘LIMIT 100’) > > query_job = client.query(QUERY) # API request > > rows = query_job.result() # Waits for query to finish > > for row in rows: > > print(**[row.name](<http://row.name/>)**)

For more information on connecting PAD to Python, look at our help article here.

Previous
Previous

The 5 Common Data Problems

Next
Next

Takeaways from the Google Cloud Next Conference