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)
| n | pi | mode |
|---|---|---|
| i64 | f64 | str |
| 1 | 3.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.
Release files for another-bigquery-magic 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| another_bigquery_magic-0.1.5.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| another_bigquery_magic-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / another_bigquery_magic-0.1.5.tar.gz
| Download URL | another_bigquery_magic-0.1.5.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8c57f8b8654c384d5aed5f0100785c1238738bee8f72536a465faa8ffedb55d
|
|
BLAKE2b-256 checksum How to use checksums |
fea64ad566761ada7adf955e8c5188866a7557aa17dec7e7374e961e9187a2cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / another_bigquery_magic-0.1.5-py3-none-any.whl
| Download URL | another_bigquery_magic-0.1.5-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
265c73fbbc074c1660796f4dab3286bf4280fb307ae7fd39fabc5d8caa06b248
|
|
BLAKE2b-256 checksum How to use checksums |
794368ec4411efab49369f778bcc008b9e5791f66c9d6e40124490005015cf87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|