Skip to main content

Unofficial IPython magic command for bigquery

Project description

another-bigquery-magic

Unofficial bigquery magic command for IPython notebook

Installation

# from pypi
$ pip install another-bigquery-magic

# alternatively, from github
$ git clone https://github.com/kota7/another-bigquery-magic.git --depth 1
$ pip install -U ./another-bigquery-magic

Usage

# Set the project ID
project_id = "<google-cloud-project-id>"
!gcloud config set project {project_id}
# If you are authenticated to the google cloud already, skip this cell.
# Otherwise, authenticate with your choice of method.

# Example 1. Authentication on colab
from google.colab import auth
auth.authenticate_user()

# Example 2. Authentication by user log-in
# Note: to access external table with google drive,
#       we also need "https://www.googleapis.com/auth/drive" in the scope
!gcloud auth application-default login --scopes="https://www.googleapis.com/auth/bigquery"

# Example 3. Authentication with a local json file
jsonfile = "<json-file-path>"
%config BigqueryMagic.localjson = jsonfile
# Load the bq magic command
%load_ext bq

# %bq magic command runs the query and returns the pandas data frame
%bq SELECT 1 AS test
Start query at 2024-01-12 15:31:07.286991
End query at 2024-01-12 15:31:10.047083 (Execution time: 0:00:02.760092, Processed: 0.0 GB)
test
0 1
# Use polars as the output type
q = "SELECT 1 AS n, 3.14 AS pi, 'test' AS mode"

%config BigqueryMagic.usepolars = True
x = %bq {q}
display(x)
print(type(x))

# Reset to pandas
%config BigqueryMagic.usepolars = False
x = %bq {q}
display(x)
print(type(x))
Start query at 2025-07-29 12:45:32.515976
End query at 2025-07-29 12:45:34.439488 (Execution time: 0:00:01.923512, Processed: 0.0 GB)
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (1, 3)
npimode
i64f64str
13.14"test"
<class 'polars.dataframe.frame.DataFrame'>


Start query at 2025-07-29 12:45:35.458804
End query at 2025-07-29 12:45:37.287104 (Execution time: 0:00:01.828300, Processed: 0.0 GB)
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
n pi mode
0 1 3.14 test
<class 'pandas.core.frame.DataFrame'>

See example.ipynb for more examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

another_bigquery_magic-0.1.5.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

another_bigquery_magic-0.1.5-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file another_bigquery_magic-0.1.5.tar.gz.

File metadata

  • Download URL: another_bigquery_magic-0.1.5.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for another_bigquery_magic-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b8c57f8b8654c384d5aed5f0100785c1238738bee8f72536a465faa8ffedb55d
MD5 07b858cd4a577cdcedc7be40ad998d36
BLAKE2b-256 fea64ad566761ada7adf955e8c5188866a7557aa17dec7e7374e961e9187a2cd

See more details on using hashes here.

File details

Details for the file another_bigquery_magic-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for another_bigquery_magic-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 265c73fbbc074c1660796f4dab3286bf4280fb307ae7fd39fabc5d8caa06b248
MD5 b4ec211adca0a33266954d3fe04a9c79
BLAKE2b-256 794368ec4411efab49369f778bcc008b9e5791f66c9d6e40124490005015cf87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page