SQL formatting#

To enable SQL formatting, install jupysql-plugin:

pip install jupysql-plugin --upgrade

Then, a “Format SQL” button will appear in JupyterLab:

Try it out#

To try it, click on the 🚀 button at the top of this page, then click on Binder:

format

Then, wait for JupyterLab to load. Once it loads, click on “Format SQL” and you’ll see that the SQL cell below is formatted!

from pathlib import Path
from urllib.request import urlretrieve

if not Path("penguins.csv").is_file():
    urlretrieve(
        "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv",
        "penguins.csv",
    )
%load_ext sql
%sql duckdb://
%%sql
select * from penguins.csv where island = 'Torgersen' limit 3
*  duckdb://
Done.
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex
Adelie Torgersen 39.1 18.7 181 3750 MALE
Adelie Torgersen 39.5 17.4 186 3800 FEMALE
Adelie Torgersen 40.3 18.0 195 3250 FEMALE