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.4.tar.gz (4.4 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.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file another-bigquery-magic-0.1.4.tar.gz.

File metadata

  • Download URL: another-bigquery-magic-0.1.4.tar.gz
  • Upload date:
  • Size: 4.4 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.4.tar.gz
Algorithm Hash digest
SHA256 ae553cd83202edcdfdcae4f4b9f4e840748cbfa13fbaaf308f6726009fc80230
MD5 ecb96a43cb04b867b1b90bf59c671e6f
BLAKE2b-256 940d6ad308a32f53fd5773eeb5c9a5e4a0a98d62d5150c4e307803dbe86873d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for another_bigquery_magic-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 78d69e25677d96d990cd3419e2c4ed8aac37edbaf9393c4d466c3f0f6e724687
MD5 359ea7ff0ac79e117ac5c374984c5600
BLAKE2b-256 77340d4f9fa7ea5c4c9e6dba8539dd167a9ecbdbbe4816d49d8cf1b3788ffdfa

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