AI Generate IPython docs instantly

IPython Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Getting Started

2 snippets

IPython interactive shell basics

Magic Commands

# Line magic (single %)
%pwd  # Print working directory
%ls   # List files
%cd /path/to/directory

# Cell magic (double %%)
%%time
sum(range(1000000))

Shell Commands

# Run shell commands with !
!ls -la
!pwd
!python --version

# Capture output
files = !ls
print(files)

Help & Inspection

3 snippets

Exploring objects and documentation

Get Help

# Question mark for help
len?
str.split?

# Double question mark for source
len??

# dir() for attributes
dir(str)

Tab Completion

# Type and press Tab
import numpy as np
np.ar<TAB>  # Shows array, arange, etc.

# Works with file paths
!cat ~/Doc<TAB>

Wildcard Search

# Find matching names
*Warning*?
str.*find*?

Common Magic Commands

4 snippets

Useful IPython magics

Timing Code

# Time single line
%timeit sum(range(1000))

# Time cell
%%timeit
total = 0
for i in range(1000):
    total += i

Run Scripts

# Run Python file
%run script.py

# Run with profiler
%run -p script.py

# Run and debug on exception
%run -d script.py

Load & Save

# Load code from file
%load script.py

# Save cell to file
%%writefile output.py
def hello():
    print("Hello, World!")

History

# Show command history
%history

# Show last n commands
%history -n 10

# Save history to file
%save mycode.py 1-10

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Variable Management

3 snippets

Working with variables

List Variables

# List all variables
%who

# List with types
%whos

# List specific types
%who str
%who int

Delete Variables

# Delete specific variable
del my_var

# Delete all variables
%reset

# Delete without confirmation
%reset -f

Store Variables

# Store to database
%store myvar

# Restore from database
%store -r myvar

# List stored
%store

Debugging

2 snippets

IPython debugger (pdb)

Start Debugger

# Automatic debug on exception
%pdb on

# Manual breakpoint
import pdb; pdb.set_trace()

# Or use IPython debugger
from IPython.core.debugger import set_trace
set_trace()

Debug Commands

# In debugger:
# n - next line
# s - step into
# c - continue
# l - list code
# p var - print variable
# q - quit
# h - help

System Interaction

3 snippets

OS and environment interaction

Environment Variables

# Set environment variable
%env MY_VAR=value

# Get environment variable
%env MY_VAR

# List all env vars
%env

Change Directory

# Change directory
%cd /path/to/dir

# Go to home
%cd ~

# Go back
%cd -

Bookmark Directories

# Create bookmark
%bookmark myproject /path/to/project

# Use bookmark
%cd myproject

# List bookmarks
%bookmark -l

Matplotlib Integration

2 snippets

Plotting in IPython

Enable Plotting

# For Jupyter notebooks
%matplotlib inline

# For interactive plots
%matplotlib notebook

# For Qt backend
%matplotlib qt

Quick Plot

import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline

x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.show()

Advanced Features

4 snippets

Power user features

Macro Recording

# Start recording
%macro mymacro 1-5

# Run macro
mymacro

# Edit macro
%edit mymacro

Paste Code

# Paste code and execute
%paste

# Paste without executing
%cpaste

Output Caching

# Access previous output
_ # Last output
__ # Second to last
___ # Third to last

# Access by line number
Out[5] # Output from cell 5
_5 # Same as above

Parallel Computing

# Start IPython cluster
!ipcluster start -n 4

# Use parallel magic
from ipyparallel import Client
rc = Client()
view = rc[:]

More Cheat Sheets

FAQ

Frequently asked questions

What is a IPython cheat sheet?

A IPython cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in IPython. It helps developers quickly look up syntax without searching through documentation.

How do I learn IPython quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important IPython concepts?

Key IPython concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my IPython code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your IPython code using AI.

Code Conversion Tools

Convert IPython to Other Languages

Easily translate your IPython code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate IPython Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week