Cell magic
Also written: magic commands
Special commands in notebooks starting with % or %% that control code execution or the environment.
Cell magic commands are special instructions used in interactive coding environments like Jupyter notebooks. They start with a single percent sign (%) for line magics or double percent signs (%%) for cell magics.
These commands are not regular Python code. Instead, they tell the notebook environment to do something specific, like timing how long a piece of code takes to run, loading data from a file, or even running code written in a different programming language. For example, `%%time` at the start of a notebook cell will measure how long the code in that cell takes to execute.
Cell magics are directives interpreted by the IPython kernel (and thus Jupyter) that extend its functionality beyond standard Python execution. Line magics (e.g., `%time`) operate on a single line of input, while cell magics (e.g., `%%time`) operate on the entire cell's content.
They provide convenient shortcuts for common tasks like system command execution (`!ls`), variable inspection (`%who`), code timing (`%timeit`), and loading data (`%store`). Their implementation involves IPython's magic system, allowing for extensibility and custom magics.
This term is relevant as frontier AI labs like Google Gemini are refining their developer tools and documentation. Improving code examples and notebook functionality, as seen in the Gemini API Cookbook, directly impacts how developers interact with and utilize these AI models.
- Gemini API Cookbook: fix(notebooks): fix syntax errors, broken code, and missing dependencies (#1334)Google · Gemini API Cookbook ·
- Google Gemini
- Google Gemini's API Cookbook includes examples that utilize cell magics to help developers run and test code interacting with their models.
- Magic methods
- In object-oriented programming, magic methods (like `__init__`) a
- Shell commands
- Shell commands are instructions given to the operating system's
Cell magics originated with IPython, an enhanced interactive Python shell that later formed the foundation for Jupyter Notebooks. They were developed to provide convenient shortcuts and extended functionality for interactive computing. Source ↗
Open a Jupyter Notebook or Google Colab. At the top of a code cell, type `%%time` and then write a simple Python loop, like `for i in range(1000000): pass`. Run the cell. The output will show you how long the loop took to execute.
The Playbook: reusable how-tos, prompts, configs and tips pulled out of the news.
- PromptRole-play a student struggling with math for AI tutor simulationSimulate a student's math struggles and uncertainty for AI tutor evaluation. · 5 min
- TemplateReusable workflow templates for healthcare teamsTeams can create and share templates for common workflows like documentation or prior authorizations. · 15 min
- TemplateTemplate for building an AI tool tailored to your workA structured approach to defining and building a custom AI tool for specific business needs. · 15 min
- TemplateEvals CSV prompt list for agent skillsA CSV file template for listing prompts used in evaluating agent skills. · 20 min
- HeuristicDouble coding agent task completion with docs linksProviding coding agents with a documentation link significantly increases their task completion rate. · 2 min
Questions people ask
- Are cell magics part of Python?
- No, cell magics are not part of the standard Python language. They are a feature provided by the IPython kernel, which is commonly used in environments like Jupyter Notebooks.
- Can I write my own cell magics?
- Yes, IPython and Jupyter allow you to define custom cell magics, enabling you to extend the notebook environment with your own specialized commands.
First seen on Subvolts Sep 7, 2026. Updated Sep 15, 2026. Written by an AI model from the items above and reviewed against them weekly; report an error.

