IPython is an enhanced Python REPL, and it’s actually the core for Jupyter notebook. In short, Jupyter is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. If you use the interactive shell a lot and you don’t know IPython, you should really check this one out!
Some of the features the IPython shell offers are:
- Comprehensive object introspection.
- Input history, persistent across sessions.
- Caching of output results during a session with automatically generated references.
- Tab completion, with support for completion of python variables and keywords, filenames, and Python functions.
- Magic commands for controlling the environment and performing many tasks.
- Session logging and reloading.
- Integrated access to the pdb debugger and the Python profiler.
- A less known feature of IPython: its architecture also allows for parallel and distributed computing.
These are just a selection of the magic commands that are built into IPython that I think you’ll like:
%cd— change the current working directory
%edit— open an editor and execute the code you typed in after closing the editor
%env— show the current environment variables
%pip install [pkgs]— install packages without leaving the interactive shell
%timeit— time the execution of Python code
Read the full list in the documentation here.
Referencing previous input and output
Another useful feature is referencing the input and output of a previous command. In and Out are actual objects. You can use the output of the 3rd command by using
Out. You can re-execute the third command with In.
You probably know the drill, but just to be complete, here’s how you install IPython with pip install:
$ pip install ipython
Although it’s often better to use a virtual environment, in this case you may want to install it system-wide or for your entire user account with
pip install --user.