In [1]:
# !pip install ipython-sql

In [2]:
from IPython.display import display_javascript
js = "IPython.CodeCell.config_defaults.highlight_modes['magic_sql'] = {'reg':[/^%%sql/]};"
display_javascript(js, raw=True)



In [3]:
%load_ext sql

In [4]:
%sql sqlite://


Out[4]:
'Connected: None@None'

In [5]:
%%sql
DROP TABLE writer;
CREATE TABLE writer(first_name, last_name, year_of_death);
insert into writer VALUES('William', 'Shakespeare', 1616);
insert into writer VALUES('Bertold', 'Brecht', 1956);


(sqlite3.OperationalError) no such table: writer [SQL: 'DROP TABLE writer;']

In [6]:
%sql select * from writer;


(sqlite3.OperationalError) no such table: writer [SQL: 'select * from writer;']

In [7]:
%%sql

insert into writer VALUES('Walt', 'Whitman', 1856);
insert into writer VALUES('Mark', 'Twain', 1907);


(sqlite3.OperationalError) no such table: writer [SQL: "insert into writer VALUES('Walt', 'Whitman', 1856);"]

In [12]:
%%sql

select * from writer order by year_of_death;


Done.
Out[12]:
first_name last_name year_of_death
William Shakespeare 1616
Walt Whitman 1856
Mark Twain 1907
Bertold Brecht 1956

In [13]:
result = %sql SELECT * FROM writer ORDER BY year_of_death;


Done.

In [15]:
type(result)


Out[15]:
sql.run.ResultSet

In [16]:
result.DataFrame()


Out[16]:
first_name last_name year_of_death
0 William Shakespeare 1616
1 Walt Whitman 1856
2 Mark Twain 1907
3 Bertold Brecht 1956

In [18]:
%matplotlib inline

result.bar()


Out[18]:
<Container object of 4 artists>
>>> print('hello')

In [ ]: