jupyter
Read, modify, execute, and convert Jupyter notebooks programmatically. Use when working with .ipynb files for data science workflows, including editing cells, clearing outputs, or converting to other formats.
When & Why to Use This Skill
This Claude skill provides comprehensive programmatic control over Jupyter Notebooks (.ipynb), enabling users to read, edit, execute, and convert files with ease. It streamlines data science workflows by automating cell modifications, output clearing, and format conversions (HTML, Markdown, Script), making it an essential tool for reproducible research, automated reporting, and maintaining clean codebases.
Use Cases
- Automated Reporting: Convert Jupyter notebooks into professional HTML or Markdown documents to share data insights with stakeholders without sharing raw code.
- Notebook Maintenance: Programmatically clear all execution outputs and reset cell counts to prepare notebooks for clean version control commits in Git.
- Workflow Automation: Seamlessly convert experimental .ipynb files into production-ready Python scripts for integration into larger software systems.
- Bulk Editing: Search for specific code patterns and update cell contents across multiple notebooks simultaneously to ensure consistency in large projects.
- Execution Pipelines: Trigger the programmatic execution of notebook cells to refresh data visualizations and analysis results as part of a CI/CD or data pipeline.
| name | jupyter |
|---|---|
| description | Read, modify, execute, and convert Jupyter notebooks programmatically. Use when working with .ipynb files for data science workflows, including editing cells, clearing outputs, or converting to other formats. |
Jupyter Notebook Guide
Notebooks are JSON files. Cells are in nb['cells'], each has source (list of strings) and cell_type ('code', 'markdown', or 'raw').
Modifying Notebooks
import json
with open('notebook.ipynb') as f:
nb = json.load(f)
# Modify nb['cells'][i]['source'], then:
with open('notebook.ipynb', 'w') as f:
json.dump(nb, f, indent=1)
Executing & Converting
jupyter nbconvert --to notebook --execute --inplace notebook.ipynb # Execute in place
jupyter nbconvert --to html notebook.ipynb # Convert to HTML
jupyter nbconvert --to script notebook.ipynb # Convert to Python
jupyter nbconvert --to markdown notebook.ipynb # Convert to Markdown
Finding Code
grep -n "search_term" notebook.ipynb
Cell Structure
# Code cell
{"cell_type": "code", "execution_count": None, "metadata": {}, "outputs": [], "source": ["code\n"]}
# Markdown cell
{"cell_type": "markdown", "metadata": {}, "source": ["# Title\n"]}
Clear Outputs
for cell in nb['cells']:
if cell['cell_type'] == 'code':
cell['outputs'] = []
cell['execution_count'] = None