IPython: Productive Interactive Computing - An advanced interactive computing environment and command shell for Python.
npx @tessl/cli install tessl/pypi-ipython@9.5.0IPython is an advanced interactive computing environment and command shell that extends the standard Python REPL with powerful features including comprehensive object introspection, persistent input history with session caching, extensible tab completion, a rich system of magic commands, configurable environments with profile switching, session logging and reloading capabilities, extensible syntax processing, integrated system shell access, easy embedding in other Python programs, and integrated access to debugging and profiling tools.
pip install ipythonimport IPythonCommon usage patterns:
from IPython import start_ipython, embed, get_ipython
from IPython.display import display, HTML, Markdown, Image, Video, Audio, Javascript
from IPython.lib.display import FileLink, YouTubeVideo
from IPython.core.magic import line_magic, cell_magic, magics_classimport IPython
# Start a full IPython session
IPython.start_ipython()
# Embed IPython in current scope for debugging
def my_function():
data = {"key": "value"}
IPython.embed() # Drops into IPython shell with access to local variables
return data
# Get current IPython instance
ipython = IPython.get_ipython()
if ipython is not None:
ipython.run_cell("print('Hello from IPython!')")IPython follows a modular architecture with several key components:
This design enables IPython to serve as both a standalone interactive environment and an embeddable component for building custom interactive applications.
Primary entry points for starting IPython sessions, embedding interactive shells, and managing the current IPython instance.
def start_ipython(argv=None, **kwargs):
"""Launch a normal IPython instance (as opposed to embedded)"""
def embed(header='', compile_flags=None, **kwargs):
"""Embed and start IPython in a given scope"""
def get_ipython():
"""Get the currently running InteractiveShell instance, or None if not in IPython"""Extensible command system providing special functionality through % (line) and %% (cell) magic commands, plus framework for creating custom magics.
@magics_class
class MyMagics(Magics):
pass
@line_magic
def my_magic(self, line):
"""A simple line magic"""
@cell_magic
def my_cell_magic(self, line, cell):
"""A simple cell magic"""Rich output formatting and media display capabilities for presenting HTML, images, videos, interactive widgets, and custom representations.
def display(*objs, include=None, exclude=None, metadata=None, **kwargs):
"""Display objects with rich formatting"""
class HTML(DisplayObject):
"""HTML display object"""
class Image(DisplayObject):
"""Image display object"""Plugin architecture for loading and managing IPython extensions that add custom functionality, magic commands, and hooks.
def load_ipython_extension(ipython):
"""Extension loading entry point"""
def unload_ipython_extension(ipython):
"""Extension unloading entry point"""
class ExtensionManager:
"""Manages loading and unloading of extensions"""Advanced terminal integration with syntax highlighting, tab completion, keyboard shortcuts, and embedding capabilities for interactive debugging.
class TerminalInteractiveShell(InteractiveShell):
"""Terminal-based interactive shell"""
def embed(header='', compile_flags=None, **kwargs):
"""Embed IPython in current scope"""Configuration management through profiles, path utilities for IPython directories, and system information functions.
def get_ipython_dir():
"""Get the IPython directory path"""
def locate_profile(profile='default'):
"""Find a profile directory"""
def sys_info():
"""Get system information"""class InteractiveShell:
"""Core interactive shell implementation"""
def run_cell(self, raw_cell, store_history=True, silent=False, shell_futures=True):
"""Execute a code cell"""
def complete(self, text, line=None, cursor_pos=None):
"""Perform tab completion"""
def object_inspect(self, oname, detail_level=0):
"""Inspect an object"""
class DisplayObject:
"""Base class for rich display objects"""
def __init__(self, data=None, url=None, filename=None, metadata=None):
pass
class Magics:
"""Base class for magic command collections"""
def __init__(self, shell=None):
pass