Jupyter with IPython

IPython is a much better interactive command line interface for Python than the default Python Shell. It supports variable auto-completion, auto-indentation, Bash Shell commands, and has many useful built-in functions and features. Greatly improves the productivity of interactive computing and software development.

Jupyter Notebook (formerly IPython Notebook) is a web-based interactive computing environment for creating Jupyter Notebook documents.Notebook is a web based IPython wrapper that makes it possible to use IPython in the browser. Thanks to the web-side data and presentation separation model and the rich text feature, Notebook can take IPython’s data presentation capabilities, which are limited by the command line, and make them fully accessible through the browser.

In 2014, Fernando PĂ©rez announced the derivation of a project from IPython called Jupyter. IPython continued to exist as the Python shell and the Jupyter kernel, while IPython Notebook and other language-independent parts were moved to the Jupyter name. Jupyter is language-agnostic, and its name is a reference to the kernel programming languages supported by Jupyter, which are Julia, Python, and R. It supports the execution environments (that is, the kernel) of dozens of languages (page archive backups, stored in the Internet Archive), which include Julia, R, Haskell, Ruby, and of course Python (via the IPython kernel).

IPython magic commands

IPython provides a number of magic commands that make operating in the IPython environment more comfortable. The magic commands all start with % or %%. Those starting with % become line commands, and those starting with %% are called unit commands. Line commands are only valid for the line where the command is located, while unit commands must appear on the first line of the unit and process the entire unit of code.

Execute %lsmagic to see the description about each command, and add ? to see a detailed description of the command.

Available line magics:
%alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cd  %clear  %cls  %colors  %config  %connect_info  %copy  %ddir  %debug  %dhist  %dirs  %doctest_mode  %echo  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %macro  %magic  %matplotlib  %mkdir  %more  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %ren  %rep  %rerun  %reset  %reset_selective  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%cmd  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

Common magic commands.

  • %magic shows detailed documentation of all magic commands
  • %time statement reports the execution time of a statement.
  • %timeit statement Execute the statement multiple times to calculate the average execution time
  • %prun statement Execute the statement via cProfile and print the parser results.
  • %run script.py Execute an external script file in ipython.
  • %pdb automatically counts to the debugger after an exception is thrown.
  • %hist Query the history of input.
  • %debug Accesses the interactive debugger from the bottom of the latest exception trace.
  • %env Display system environment variables.
  • %reset Clear namespace
  • %cd Enter directory command