IPython Notebook Basics

Project directory

  • IPython Notebooks are just files (.ipynb) on your file system
  • The Notebook server is aware of Notebooks in a single directory, which we call the Notebook directory
  • If you cd to a Notebook directory and type:

      jupyter notebook
    
    

    you will see the Notebooks in that directory in the dashboard

Notebook files

Notebook files:

  • Are just that - files (.ipynb) on your file system
  • Contain JSON data
In [7]:
import nbformat

with open('Notebook Basics.ipynb') as f:
    nb = nbformat.v4.reads_json(f.read())    
In [9]:
nb.cells[0:5]
Out[9]:
[{u'cell_type': u'markdown',
  u'metadata': {u'slideshow': {u'slide_type': u'slide'}},
  u'source': u'# IPython Notebook Basics'},
 {u'cell_type': u'markdown',
  u'metadata': {},
  u'source': u'## Project directory'},
 {u'cell_type': u'markdown',
  u'metadata': {},
  u'source': u'* IPython Notebooks are just files (`.ipynb`) on your file system\n* The Notebook server is aware of Notebooks in a single directory, which we call the **Notebook directory**\n* If you cd to a Notebook directory and type:\n\n        jupyter notebook\n\n  you will see the Notebooks in that directory in the dashboard'},
 {u'cell_type': u'markdown',
  u'metadata': {u'slideshow': {u'slide_type': u'slide'}},
  u'source': u'## Notebook files'},
 {u'cell_type': u'markdown',
  u'metadata': {},
  u'source': u'Notebook files:\n\n* Are just that - files (`.ipynb`) on your file system\n* Contain JSON data'}]
  • Embed code, Markdown text, LaTeX equations, images
  • Are version control friendly: post your Notebooks on GitHub
  • Can be viewed online by anyone at http://nbviewer.org

IPython Notebooks can also be exported to .py files (see "File:Download As" menu item). You can tell the Notebook server to always save these .py files alongside the .ipynb files by starting the Notebook as:

ipython notebook --script

You can import Notebooks from the main Dashboard or simply by copying a Notebook into the Notebook directory.

Overview of the UI

  • Dashboard
  • Notebook area and cells
  • Menu
  • Toolbar

Cell types

  • Code
  • Markdown
  • Raw text

Keyboard shortcuts

  • Shift-Enter to run a cell
  • Ctrl-Enter to run a cell in place
  • All other keyboard shortcuts have the form: Ctrl-m ?
  • Show all keyboard shortcuts using Ctrl-m h