ipynb to pdf
  • Notebooks
  • Format
  • Jupyter

What Is an .ipynb File? Inside the Jupyter Notebook Format

An .ipynb file is JSON, not code. Here is what a Jupyter notebook actually stores, how to open one without Jupyter, and what to check before you trust it.

The IPYNB to PDF team6 min readUpdated

An .ipynb file is a Jupyter notebook: a JSON document that stores a session as an ordered list of cells, together with the output each code cell produced. It is not a script, not an archive and not a compiled artifact — it is a transcript, written down in a format that both Jupyter and a dozen other tools can read.

That distinction explains most of the confusion around the extension. A .py file is the program. An .ipynb file is the program plus the prose around it plus the results of the last run.

What IPYNB stands for

IPYNB is short for IPython Notebook. The extension was introduced by IPython, the interactive Python shell whose notebook feature grew into Project Jupyter. The application was renamed, the file extension was not, which is why the format is still called IPYNB even though a notebook can now run Python, R, Julia, SQL or JavaScript.

The name is also why search results mix “IPYNB” and “Jupyter notebook” so freely: they are the same file.

What is actually inside the file

Open an .ipynb in a text editor and you get JSON. The shape is stable across versions:

{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": ["# Quarterly churn\n", "\n", "Cleaned with **pandas 2.2**."]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {},
      "outputs": [
        {
          "data": { "text/plain": ["142"] },
          "execution_count": 3,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": ["len(df)"]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": { "name": "python", "version": "3.12.4" }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}

Four things are worth noticing.

cells is the document. Everything visible in the notebook lives in this array, in order. There is no hidden second copy of the content.

source is a list of lines. A string would be simpler, but the list format makes diffs readable and matches how the editor stores text. Tools that write notebooks must keep it as a list of strings.

Outputs are stored, not recomputed. The 142 above is a value saved when the cell last ran. Opening the notebook tomorrow shows 142 even if the data has changed since. This is the single most important thing to understand about .ipynb files: they are snapshots, not live documents.

nbformat and nbformat_minor are the schema version. Version 4 is current. Version 3 files, still found in older course material, keep their cells under worksheets instead of at the top level.

The three cell types

Cell type What it holds How it is rendered
code Source code, execution count, outputs Syntax-highlighted, with results below
markdown Prose, headings, lists, tables, LaTeX Rendered as document text
raw Text passed through untouched Not rendered; used by exporters and templates

Markdown cells are where a notebook becomes a report. Code cells are where it becomes a program. Raw cells are the escape hatch — a LaTeX block, an HTML fragment or a directive for a converter.

What an output can contain

A code cell’s outputs array holds one entry per result, and each entry has an output_type:

  • stream — stdout or stderr, including ANSI colour codes.
  • execute_result — the value of the last expression, with an execution count.
  • display_data — rich output from display() or a plotting library.
  • error — a traceback, with the error name and the full stack.

Rich outputs carry a MIME bundle: several representations of the same value, and the viewer picks the best one it supports. A pandas DataFrame typically arrives as text/html and text/plain; a matplotlib figure as image/png plus text/plain; a SymPy expression as text/latex. This is why the same notebook can look different in JupyterLab, on GitHub and in a PDF export — each renderer chooses a different representation.

Notebook metadata

The top-level metadata object describes the environment rather than the content:

  • kernelspec — which kernel ran the notebook, and its display name.
  • language_info — language and version, used for syntax highlighting.
  • colab — Colab-specific settings, present in notebooks downloaded from Google Colab.
  • widgets — state for interactive Jupyter widgets.

None of this is required to read the content, but it matters when you merge, convert or share a notebook: a merged file with two conflicting kernelspec blocks will open with the wrong kernel.

Attachments: images that live inside the file

Markdown cells can embed an image without a URL by storing it in cell.attachments as base64. This is how screenshots pasted into a notebook survive being emailed to someone else. Converters must decode those attachments; a tool that ignores them produces a PDF with broken image links.

nbformat 4 versus nbformat 3

Version 4, released with Jupyter, flattened the structure: cells moved to the top level and outputs became simpler. Version 3 kept cells in worksheets, used input instead of source, and encoded outputs differently.

Modern tools write version 4. Older notebooks still exist in course packs and archived repositories, so a converter that only understands version 4 will refuse some perfectly valid files. The browser converter handles both, as does nbconvert when reading with as_version=4.

How to open an .ipynb without Jupyter

You do not need a kernel to read a notebook.

  • GitHub and GitLab render notebooks in the browser, including outputs and plots.
  • VS Code opens .ipynb files in its notebook editor with no Python extension required for viewing.
  • The IPYNB viewer renders a notebook as a document — markdown, code, outputs, tables and math — without converting it.
  • A text editor shows the raw JSON, which is the fastest way to inspect metadata or recover a cell.
  • Python can read it in one line:
import nbformat

nb = nbformat.read("notebook.ipynb", as_version=4)
print(nb.nbformat, nb.nbformat_minor)
for cell in nb.cells:
    print(cell.cell_type, cell.source[:60])

That last snippet is also the basis for scripted merges, splits and conversions.

Is it safe to open an .ipynb file?

The file itself is data, but its outputs can contain HTML, JavaScript and SVG — and a notebook you execute can run arbitrary code. Treat a notebook like an executable you did not write:

  • Reading and converting is safe when the tool does not execute cells. The browser converter only parses stored content.
  • Running is not safe. A notebook can delete files, read credentials or make network requests. Jupyter’s trust system warns you, but it is not a sandbox.
  • Rendered HTML outputs are sanitised by Jupyter, but a converter that injects raw output HTML without sanitising it can be exploited. This site sanitises markdown and output HTML with DOMPurify before rendering.

If a notebook came from someone you do not know, read it before you run it — and prefer a viewer or a converter that never executes anything.

What you can turn it into

The JSON is a source format, not a delivery format. From here you can produce:

Each format answers a different question. The .ipynb file answers “what happened in this session?” — which is exactly the question a PDF cannot answer, and exactly why both are useful.