Free — no signup required

Notebooks in Production: When to Graduate to Scripts

2 min read

The Exploration-to-Production Boundary

Notebooks are excellent for exploration, prototyping, and communication. They are poor choices for production systems. Understanding when and how to make the transition is a mark of engineering maturity.

Notebooks are the right tool when:
- You are exploring an unfamiliar dataset for the first time.
- You are prototyping a model and iterating quickly on feature engineering.
- You are producing a report or analysis to share with stakeholders who need to see code, output, and explanation together.

Notebooks become a liability when:
- The same notebook needs to run automatically on a schedule (e.g., nightly retraining).
- Multiple engineers need to collaborate on the same logic using version control (git diffs on .ipynb JSON are nearly unreadable).
- The code needs to be unit tested.
- The logic needs to be imported and reused by other modules.

The Graduation Pattern

The standard workflow is:

  1. Explore in a notebook. Iterate freely. Use hidden state. Make a mess.
  2. Extract the clean logic. Once you understand the problem, move the stable, tested code into .py modules (e.g., feature_engineering.py, train.py).
  3. Import back into the notebook for final documentation and visualization, or replace the notebook entirely with a script orchestrated by a tool like Airflow, Prefect, or a simple cron job.
  4. Use papermill if you genuinely need parameterized notebook execution in production — it lets you inject parameters and run notebooks as pipeline steps, capturing outputs. This is a pragmatic middle ground.
Interview Tip

A common platform engineering interview question is: "A data science team wants to run their Jupyter notebooks as part of a CI/CD pipeline. How would you approach this?" The answer has two layers: (1) short-term — use papermill or nbconvert --execute to run notebooks as pipeline steps and fail the build if any cell errors; (2) long-term — work with the team to extract notebook logic into testable Python modules, keeping notebooks only for reporting. This shows you can meet teams where they are while steering toward better practices.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free