Skip to main content

Jupyter Notebook to Python Script Converter

Paste your .ipynb JSON to convert it to a clean Python script. Remove magic commands, include markdown cells as comments, and choose your cell separator style.

✓ Magic command removal ✓ Markdown as comments ✓ VS Code # %% cells ✓ Conversion stats

Frequently Asked Questions

Why convert a Jupyter notebook to a Python script?▼

Jupyter notebooks are great for exploration and visualization, but they have limitations in production: they can't be imported as modules, are difficult to version control cleanly (they store outputs in JSON), don't work well with CI/CD pipelines, and can have hidden state from out-of-order cell execution. Converting to a .py script makes code importable, diffable, testable with pytest, runnable from the command line via cron or task schedulers, and compatible with code review workflows.

What are magic commands and why remove them?▼

Magic commands are Jupyter-specific syntax: line magics start with % (e.g., %matplotlib inline, %timeit, %load_ext) and cell magics start with %% (e.g., %%bash, %%sql). Shell commands start with ! (e.g., !pip install, !ls). These are interpreted by the IPython kernel and are not valid Python syntax — they will raise SyntaxError if run as a plain .py file. Remove them when converting to a script, or replace %matplotlib inline with matplotlib.use('Agg') and !pip install X with a requirements.txt entry.

What does the # %% cell separator do?▼

The # %% comment is a special marker recognized by VS Code (with the Jupyter extension) and Spyder IDE as a 'code cell' boundary. This means your converted .py file can still be run interactively cell-by-cell inside VS Code — just like a notebook — without being a .ipynb file. Click 'Run Cell' above any # %% block to execute just that section. This gives you the best of both worlds: a clean .py file for version control and CI/CD, with notebook-like interactivity during development.

How do I run a converted script in production?▼

After conversion, run the script with: python script.py. For scheduled jobs, use cron (Linux/Mac) or Task Scheduler (Windows). For parameterized runs, consider Papermill (papermill notebook.ipynb output.ipynb -p param value) or replace hardcoded values with argparse. For ML pipelines, tools like Prefect, Airflow, or Dagster can orchestrate .py scripts as pipeline tasks. Always test the script in a clean virtual environment first to catch any missing dependency or implicit global state.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →