📊
BigQuery
Got some data in BigQuery you want to use?
Getting data out of BigQuery and into Databutton is pretty straight forward. The largest obstacle could be the get the necessary permissions to create a service account in Google Cloud. If you are not the administrator of the project, you might need to do this step for you, or to give you the permissions to do so yourself.
1. Create a service account in the Google Cloud Console



2. Give the right permissions

3. Find your service account in the list, click it, and generate a key


4. Open the .json file you downloaded and copy the content

5. In your Databutton App, click on the Configure button in the bottom left corner

5. Paste the .json content into a new secret and click save

6. Install the Google Python packages you will need

7. Call BigQuery and use the data
Here we call BigQuery and put the results in a Databutton dataframe.
import json
import databutton as db
import pandas_gbq as pd
from google.oauth2 import service_account
bigquery_key = json.loads(db.secrets.get("BigQuery"))
credentials = service_account.Credentials.from_service_account_info(
bigquery_key,
)
project_id = "YOUR GOOGLE PROJECT"
query = """
SELECT _ FROM _ WHERE _
"""
df = pd.read_gbq(
query, project_id=project_id, dialect="standard", credentials=credentials
)
db.storage.dataframes.put("myDf")
Last modified 1mo ago