%%bqsql cell magics#

The BigQuery DataFrames (aka BigFrames) package provides a %%bqsql cell magics for Jupyter environments.

To use it, first activate the extension:

%load_ext bigframes

Now, use the magics by including SQL in the body.

%%bqsql
SELECT * FROM `bigquery-public-data.usa_names.usa_1910_2013`

The output DataFrame can be saved to a variable.

%%bqsql mydf
SELECT * FROM `bigquery-public-data.usa_names.usa_1910_2013`

You can chain cells together using format strings. DataFrame objects are automatically turned into table expressions.

%%bqsql
SELECT sum(number) as total_count, name
FROM {mydf}
WHERE name LIKE 'Tr%'
GROUP BY name
ORDER BY total_count DESC
Query processed 88.1 MB in a moment of slot time.