iPython SQL Extension Demo

This notebook shows how iPython SQL Extension works.

Setup

  • Install Anaconda from https://www.continuum.io/downloads
  • Install iPython SQL Extension
    pip install ipython-sql
    
  • Set the account name, user name and password to the environment variables to SF_ACCOUNT, SF_USER and SF_PASSWORD, respectively
  • Start Jupyter notebook
    jupyter notebook
    

In [1]:
%load_ext sql


/home/stakeda/anaconda3/envs/t/lib/python3.5/site-packages/IPython/config.py:13: ShimWarning: The `IPython.config` package has been deprecated. You should import from traitlets.config instead.
  "You should import from traitlets.config instead.", ShimWarning)
/home/stakeda/anaconda3/envs/t/lib/python3.5/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
  warn("IPython.utils.traitlets has moved to a top-level traitlets package.")

In [2]:
import os
account=os.getenv('SF_ACCOUNT')
user=os.getenv('SF_USER')
password=os.getenv('SF_PASSWORD')

In [3]:
%sql snowflake://$user:$password@$account/testdb/public


Out[3]:
'Connected: admin@testdb/public'

Now you can run any sql commands using %%sql extension. Enjoy!


In [4]:
%%sql
    select * from users limit 10


10 rows affected.
Out[4]:
userid username firstname lastname city state email phone likesports liketheatre likeconcerts likejazz likeclassical likeopera likerock likevegas likebroadway likemusicals
1 JSG99FHE Rafael Taylor Kent WA Etiam.laoreet.libero@sodalesMaurisblandit.edu (664) 602-4412 True True None False True None None True False True
2 PGL08LJI Vladimir Humphrey Murfreesboro SK Suspendisse.tristique@nonnisiAenean.edu (783) 492-1886 None None None True True None None True False True
3 IFT66TXU Lars Ratliff High Point ME amet.faucibus.ut@condimentumegetvolutpat.ca (624) 767-2465 True False None False None False True None None True
4 XDZ38RDD Barry Roy Omaha AB sed@lacusUtnec.ca (355) 452-8168 False True None False None None None None None False
5 AEB55QTM Reagan Hodge Forest Lake NS Cum@accumsan.com (476) 519-9131 None None True False None None True True False True
6 NDQ15VBM Victor Hernandez Naperville GA turpis@accumsanlaoreet.org (818) 765-4255 False None None True None True True True True True
7 OWY35QYB Tamekah Juarez Moultrie WV elementum@semperpretiumneque.ca (297) 875-7247 None None None True True False None None False False
8 AZG78YIP Colton Roy Guayama AK ullamcorper.nisl@Cras.edu (998) 934-9210 None None True True None True False None False False
9 MSD36KVR Mufutau Watkins Port Orford MD Integer.mollis.Integer@tristiquealiquet.org (725) 719-7670 True False None False True None None None False True
10 WKW41AIW Naida Calderon Waterbury MB Donec.fringilla@sodalesat.org (197) 726-8249 False False False None False True None True None None

In [ ]: