ipynb to pdf

PY to IPYNB

Python script to notebook,in one drop.

Drop in a .py file and download a valid .ipynb notebook: # %% cell markers become cells, [markdown] blocks come back as prose, and scripts without markers are split at their top-level definitions. Nothing is uploaded anywhere.

Converted in your browser — the script is never uploaded. You can also drop it anywhere on this page.

  • Jupytext percent
  • # %% cells
  • VS Code
  • Spyder
  • nbconvert script
  • Python 3

0 bytes uploaded

Parsing and notebook assembly happen on your device.

nbformat 4.5 output

The current notebook format every Jupyter tool reads.

# %% cell markers

Percent markers, Spyder separators and In[] prompts all open a cell.

100% of the code kept

Code is copied unchanged — indentation, magics and all.

What the notebook keeps

Cells first, prose where it belongs.

The converter reads the script as text and rebuilds its structure, so the result is a real nbformat file you can open, run and commit — not an empty wrapper around one blob of code.

Cell markers become cells

A line that opens with # %% — with or without a space, with or without a title — starts a new code cell, exactly like the percent format nbconvert and Jupytext write.

Commented prose returns as markdown

Inside a # %% [markdown] block the comment prefixes are removed, so headings, lists and notes that a script export turned into comments come back as markdown cells.

Plain scripts are split too

No markers? The script is split at its top-level def, class and decorator boundaries, so a module becomes a series of cells instead of one wall of code.

Code copied unchanged

Everything else passes through as written, including magics like %matplotlib inline and shell lines like !pip install, which are valid notebook content.

Deterministic output

Cell ids are derived from the cell text rather than random, so converting the same script twice produces the same file — and a diff shows the code, not the noise.

Ready to open and run

The file is nbformat 4.5 with a Python 3 kernelspec and no stored outputs: open it in Jupyter, JupyterLab, Colab, Kaggle or VS Code and run all cells.

Compatibility

Reads the scripts your tools already write.

Anything that is valid Python converts; these are the separators and edge cases the reader knows about.

Cell separators recognised

  • # %% and #%%
  • # %% [markdown] / [md]
  • # %% [raw]
  • # <codecell> (Spyder)
  • # In[3]: / # In[]: prompts

Split without markers

  • top-level def and async def
  • class bodies with their decorators
  • imports and globals stay in the first cell
  • one cell when the script is a flat list of statements

Notebook output

  • nbformat 4.5 with cell ids
  • Python 3 (ipykernel) metadata
  • execution_count: null, no outputs
  • UTF-8 source, any language in comments and strings

Known limits

  • outputs cannot be invented — run the notebook to fill them
  • a leading comment header becomes the first markdown cell
  • percent titles (# %% Setup) are not kept as cell names
  • IPython magics still need a real kernel to run

How it works

Three steps to a notebook.

Drop in a .py file and download a valid .ipynb notebook: # %% cell markers become cells, [markdown] blocks come back as prose, and scripts without markers are split at their top-level definitions. Nothing is uploaded anywhere.

  1. 01

    Drop the script in

    Choose a .py file or drag it onto the page; it is read on your device and the notebook is assembled immediately.

  2. 02

    Check the cells

    The preview shows the notebook JSON: one cell per separator, markdown restored, everything else copied unchanged.

  3. 03

    Download the .ipynb file

    Save script.ipynb next to your project and open it in Jupyter, JupyterLab, Colab or VS Code — then run the cells.

Every route from PY to IPYNB

Five ways to turn a Python script into a notebook, from the browser converter above to the tooling built into Jupytext, VS Code and Jupyter itself — pick the one that fits where you already are.

jupytext --to notebook

The command-line standard: jupytext --to notebook script.py writes script.ipynb beside it, and --set-formats py:percent,ipynb pairs the two files so every save updates both. It needs Python and an install — the route to choose when the script already lives in a project you control.

VS Code

VS Code reads a percent script as cells: the # %% lines become cell boundaries you can run in the interactive window, and the Jupyter extension converts the open file to a notebook from the command palette. Convenient when the script is already open — little use when it is a download sitting in your file manager.

Jupyter's own menus

Jupyter Notebook and JupyterLab open a notebook with File → Open or the upload button; Colab uses File → Upload notebook. That is the second half of every route on this page: the converter produces the file, Jupyter opens it.

Google Colab's open menu

Colab can open a .py file, but only as a text editor view — no cells, no markdown. Convert the script to .ipynb here first, then upload it in Colab to get the real notebook experience.

py2nb, for build steps

A small Python package that turns scripts documented with markdown into notebooks. Handy inside a build pipeline; for a one-off conversion there is nothing to install behind the converter at the top of this page.

In a hurry? Use the converter at the top.

The browser converter above reads the same scripts as every route on this page and produces the same nbformat 4.5 notebook — with nothing installed and nothing uploaded.

What the notebook keeps (and what it drops)

  • Code as code — every statement copied unchanged, in script order.
  • Markers as cells — # %%, #%%, # and # In[3]: all open a cell.
  • Prose as markdown — commented [markdown] blocks lose their # prefixes.
  • Structure as cells — marker-less scripts split at top-level definitions.
  • A clean header — a Python 3 (ipykernel) kernelspec and nbformat 4.5 metadata.
  • No outputs — results are re-run, not restored; execution_count stays null.

FAQ

PY to IPYNB: frequently asked questions

Short answers about converting a Python script to a Jupyter notebook — how cells are found, what happens to comments, and whether the notebook runs as-is.

How do I convert PY to IPYNB?

Use the converter at the top of this page: choose or drop in a .py file and the browser turns it into a notebook — cell markers split it into cells, commented prose becomes markdown, and the code is copied unchanged. Then download the .ipynb file and open it in Jupyter, JupyterLab, Colab or VS Code. No upload, no install and no terminal involved.

How do I convert a Python script to a Jupyter notebook on the command line?

Run jupytext --to notebook script.py, which writes script.ipynb next to it and can pair the two files so every save updates both. Jupytext is a Python package, so it needs an install — this page does the same job in the browser, with nothing to set up.

How does the converter decide where one cell ends and the next begins?

If the script contains cell separators — # %%, #%%, # <codecell> or # In[3]: — each one opens a new cell, and a [markdown] separator makes it a markdown cell. With no separators at all, the script is split at its top-level def, class and decorator boundaries, with imports and top-level statements staying in the first cell.

Do I need to add # %% markers to my script first?

No. Markers give the most faithful cells, but a plain module converts fine without them — the reader splits it at top-level definitions. Add markers only where you want the cell boundaries to fall somewhere else.

What happens to comments in my script?

They stay exactly where they are. A normal comment is part of its code cell and is copied unchanged. Comments turn into markdown in one case only: inside a # %% [markdown] block, where the prefix is stripped and the text becomes proper markdown.

Does the converted notebook run as-is?

The code is copied unchanged in script order, so yes — run all cells and it behaves like the script did. Two honest caveats: there are no stored outputs to begin with, so you have to run the cells, and Jupyter magics like %matplotlib inline keep working only inside a real IPython kernel.

Can I open the result in Google Colab?

Yes. In Colab use File → Upload notebook and pick the .ipynb file. Colab accepts .py files too, but opens them as plain text — the converted notebook is the version that gets cells, markdown and a kernel.

How is this different from jupytext --to notebook?

Jupytext is the right tool inside a project: it can pair a script and a notebook so every save writes both files. This converter runs in the browser instead — nothing is installed, nothing is uploaded, and it works on any machine, which is useful when a script lands in your inbox and you just want a notebook out of it.

Is my script uploaded when I convert it here?

No. The file is read with the browser File API and turned into a notebook inside the tab. You can disconnect from the network after the page loads and the conversion still works — which is also the practical proof that nothing is uploaded.

Does converting IPYNB to PY and back restore my original notebook?

The code comes back intact, but the round trip is not a restore: outputs and execution counts are gone (the script never contained them), and markdown returns as markdown only where it was written as a commented [markdown] block. Use it to move working code into a notebook, not to recover a notebook whose .ipynb file is lost.

Turn that script into a notebook and run it cell by cell.

Drop it in, download the .ipynb and open it in Jupyter — the code is already there; you only add the outputs you want.

Convert a script to IPYNB