Converting a notebook to a Python script
When you convert a .ipynb to .py, the code cells come out as plain Python and the markdown cells become comments. Each cell gets a # %% marker — that's the cell delimiter VS Code and Spyder use for their interactive Python mode, so the file feels like a notebook there too.
Why bother converting?
Notebooks are great for exploration, but awkward for everything that comes after. Git diffs on .ipynb files are a mess — the format stores output blobs, execution counts, and metadata that change every time you run a cell, even if the actual code didn't. A .py file gives you a clean diff where only code changes show up.
Running in production is the other big reason. Cron jobs, Airflow DAGs, Docker containers, GitHub Actions — they all work with Python scripts natively. Getting a notebook into that kind of pipeline usually means converting it first. And for code review, a PR reviewers can read as plain text beats one where they need to install a Jupyter extension.
How to use it
- Upload your
.ipynbfile above — drag and drop or click "Choose File". - The conversion runs instantly in your browser.
- Download the
.pyfile or copy it to your clipboard.
Nothing is sent to a server. The whole thing happens locally in your browser.
How the cells map across
Code cells are exported as-is. Markdown cells become commented lines under a # %% [markdown] header. Raw cells get the same treatment under # %% [raw]. Cell outputs aren't included — they're runtime results, not source code, so they don't belong in a script file.
One thing to watch: Jupyter magic commands like %matplotlib inline or !pip install don't work outside of Jupyter. You'll need to replace those with their plain Python equivalents before running the script in a regular environment.
Frequently asked questions
Yes, as long as the required packages are installed. The output includes a standard shebang line and encoding declaration. The only thing that might trip you up is Jupyter magic commands like %matplotlib, %%time, and similar, which you'd need to replace or remove for a plain Python environment.
Yes, that's exactly what the # %% markers are for. Open the .py file in VS Code with the Python extension installed and you'll see "Run Cell" buttons above each marker. It runs through a Jupyter kernel, so it behaves just like a notebook.
The output is very similar. The difference is that nbconvert requires Python and Jupyter installed; this runs in your browser. If you're batch-converting many notebooks locally, nbconvert is the right tool. For a quick one-off when you don't want to touch the command line, this is faster.
Yes. Download the notebook as .ipynb from Colab (File → Download → Download .ipynb) or Kaggle, then upload it here. Both platforms use the standard notebook format.
Other notebook tools
Need a different format?