Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Python Land
  • Python Tutorial
  • Courses
  • Blog
  • Contact
  • Log in
Home » Tips & Tricks » Using IPython
IPython magic commands %timeit, %run and %who float out of a magician's top hat

Using IPython

By Erik van Baaren · Published December 18, 2020 · Updated November 10, 2026

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!

Table of Contents

  • 1. IPython vs the standard Python REPL
  • 2. IPython features
  • 3. Magic commands
  • 4. Referencing previous input and output
  • 5. Install IPython

IPython vs the standard Python REPL

The standard Python REPL has improved a lot. Since Python 3.13, it has colored prompts and error messages, lets you edit a whole block of code (like a function or a loop) at once, recalls that block from history as one piece, and has a paste mode (press F3) for pasting larger chunks of code. Python 3.14 added syntax highlighting while you type. So for quick experiments, the built-in REPL is now quite pleasant.

IPython still goes further. It has magic commands, numbered input and output you can refer back to, better object inspection with ? and ??, and a history that survives restarts. If you spend a lot of time in an interactive shell, IPython is worth it.

IPython features

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.

Magic commands

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
  • %time and %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 2nd command by using Out[2]. In[2] gives you the code you typed as a string, and the magic command %rerun 2 runs it again. Here’s a short session:

In [1]: numbers = [3, 1, 2]

In [2]: sorted(numbers)
Out[2]: [1, 2, 3]

In [3]: Out[2]
Out[3]: [1, 2, 3]

In [4]: In[2]
Out[4]: 'sorted(numbers)'

In [5]: %rerun 2
=== Executing: ===
sorted(numbers)
=== Output: ===
Out[5]: [1, 2, 3]

In [6]: len?
Signature: len(obj, /)
Docstring: Return the number of items in a container.
Type:      builtin_function_or_method

The last command shows object introspection: put a question mark after any object, function, or module to see its documentation. Two question marks also show the source code, if it’s available.

Install IPython

If you want to use IPython inside a project, install it in the project’s virtual environment with pip install. That way, IPython can import all the packages of your project:

$ pip install ipython

If you’d rather have IPython available everywhere, install it as a tool. With uv, you can install it once, or start it without installing anything:

$ uv tool install ipython
$ uvx ipython

With pipx, that’s pipx install ipython. Don’t use pip install --user for this: on many Linux distributions and on Homebrew’s Python, pip refuses to install outside a virtual environment. Keep in mind that a globally installed IPython runs in its own environment, so it can’t import the packages from your project’s virtual environment.

Erik van Baaren

Erik is the owner of Python Land and the author of many of the articles and tutorials on this website. He's been working as a professional software developer for 25 years, and he holds a Master of Science degree in computer science. His favorite language of choice: Python! Writing good articles takes time and effort. Did you like this tutorial? You can buy him a coffee to show your appreciation.

More about Erik

Try this yourself, right now

Get more out of the Python REPL

The same topic as an interactive lesson: short explanation, then code you run and change in your browser, with instant feedback.

Open the interactive lesson

Free to start. Certificates and AI help with Guided.

Monty, your Python learning guide, smiling and waving

Subscribe to my newsletter for Python news, tips, and tricks!

Footer subscribe

  • Home
  • Python Courses
  • Privacy Policy
  • About Us
  • Contact us
©2026 Python Land - All rights reserved
Python Land is not affiliated with Python.org or the Python Software Foundation
  • Free Tutorial
    • Install Python
      • Online Python Interpreter
      • How To Open Python on Windows, Mac, Linux
    • Introduction to Python
      • The Python REPL
      • Python Variable
      • Python String
      • Python Print function
      • Python Booleans
      • For-loop and While-loop
      • Python Functions
      • Your First Python Program
      • Python Comments
    • Creating Python Programs
      • The Best Python IDE
      • Installing VSCode
      • VSCode Python Extensions
      • VSCode GUI Tour
      • Python in VSCode: Running and Debugging
    • Classes and Objects in Python
      • Python Constructor
      • Python Inheritance
    • Structure Your Project
      • Python Modules And Importing
      • Python Packages
    • Python Data Types
      • Python Integer
      • Python Float
      • Python Tuple
      • Python List
      • Python Set
      • Python Dictionary
    • Language Deep Dives
      • Python Try Except (Exceptions)
      • Python Functions: Advanced Concepts
      • List Comprehension
      • Python Iterator
      • Python Range
      • Python Docstrings
      • Python pass (Do Nothing)
    • Interaction with the OS
      • Python Read And Write File
      • Python Subprocess: Run External Commands
    • Venvs / Package Management
      • Working With Python’s venv
      • Pip install: the Python package manager
      • Python Poetry: Package and venv Management Made Easy
      • Python Pipenv: Another Package Manager
      • Pipx: Safely Install Packages Globally
    • Python Concurrency
      • The Python GIL (Global Interpreter Lock)
      • Setting the Baseline
      • Python Threading
      • Python Multiprocessing
    • Data Processing with Python
      • Working With JSON
        • JMESPath Python: JSON Query Language
      • Python YAML: How to Load, Read, and Write YAML
      • Python CSV: Read And Write CSV Files
    • Migrating From Python 2 to 3
      • Check Python Version On The Command-Line
      • How to Migrate To Python 3
      • Python 3 Advantages
    • Using The Unix Shell
      • Basic Linux Commands
      • Bash Scripts
      • Using the Find Command in Linux
      • Unix Pipes
      • Process and Highlight JSON with jq
      • Using the Bash History
      • Bash Multiprocessing
    • Deployment
      • PyInstaller: Create An Executable From Python Code
      • How To Use Docker To Containerize Your Python Project
      • Automatically Build and Deploy Your Python Application with CI/CD
      • Guerrilla Scale Your Web Application
    • Data Science
      • Jupyter Notebook
      • NumPy: Getting Started Tutorial
    • Python Learning Resources
  • Python Courses
  • Blog
  • Login / Register