or drop an .ipynb file here, paste its JSON or an https:// link
Cell markers
IPython syntax
Markdown cells

Open a Jupyter notebook (.ipynb) or load the sample. The file stays on your device and no code is run.

Files never leave your browserHow?

The code cells of a Jupyter notebook become one Python script you can run, import or put under version control. Markdown turns into comments, and IPython-only lines such as %matplotlib inline or !pip install are commented out so the script runs in plain Python.

Last updated:

How it works

  1. Choose the notebook

    Press Choose a notebook or drop the .ipynb. The script appears at once, with syntax colours.

  2. Pick the style

    Set Cell markers, what happens to IPython syntax, and whether Markdown cells come along As comments or Leave out.

  3. Save the script

    Press Download .py, or Copy to paste the code into your editor. The file takes the notebook’s name.

Features

  • Cells you can run again

    The default # %% markers are the percent format of Jupytext: VS Code, PyCharm and Spyder show each block as a runnable cell, and Jupytext can turn the script back into a notebook.

  • Magics made safe

    Comment out turns %magics, %%cell magics, !shell commands and help lookups like df? into comments, so python script.py does not stop with a SyntaxError.

  • nbconvert-identical option

    Choose # In[ ]: and get_ipython() to get exactly what jupyter nbconvert --to script writes; our output was compared byte for byte with nbconvert 7.17.

  • Other kernels

    R, Julia, Scala and other kernels keep their code untouched; the file gets the kernel’s extension (.r, .jl…) and the comment style of the language (#, //, --).

  • Strings stay intact

    A line inside a triple-quoted string that starts with % or ! is text, not a magic, and is left alone.

Limits & privacy

Notebooks of up to 100 MB open here; the script itself is plain text and usually a few kilobytes. IPython syntax is recognized only for Python kernels: in other kernels lines starting with % or ! are left as written. Comment out and get_ipython() handle a line that starts with %, %%, ! or !!, an assignment like files = !ls or x = %time f(), and help lookups (name? or ?name); other IPython shortcuts such as autocall (/func arg) are kept unchanged.

The notebook is converted in this tab and is not uploaded. See the privacy page.

Example: train.ipynb starts with %pip install xgboost and %matplotlib inline and has six code cells between Markdown notes. Download .py gives train.py with six # %% cells, the notes as comments, and both magic lines commented out — python train.py runs without IPython.

FAQ

How do I convert .ipynb to .py?

Open the notebook here and press Download .py. In a terminal the same is jupyter nbconvert --to script notebook.ipynb, which needs Jupyter installed.

What happens to %matplotlib inline and !pip install?

With Comment out they become # %matplotlib inline and # !pip install …: the script runs in plain Python. With get_ipython() they become get_ipython().run_line_magic(…) and get_ipython().system(…) calls, which need IPython.

Are outputs included?

No, outputs are not included in the .py file. A script holds code only; charts, tables and printed text are results of running it. To keep them, use IPYNB to HTML or IPYNB to Markdown.

Can I turn the .py back into a notebook?

Yes, the .py turns back into a notebook if you keep the # %% markers: open the file in VS Code and use Export as Jupyter Notebook, or run jupytext --to notebook script.py.

What about raw cells?

Raw cells become comments in every style. nbconvert pastes them into the script as they are, which usually breaks it; this is the one place where # In[ ]: output differs from nbconvert.

Can I just look at the notebook first?

Yes, the notebook can be viewed first in the Jupyter Notebook Viewer, which shows code, Markdown and outputs together.

Related tools