Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
About Article
Analyze Data
Archive
Best Practices
Better Outputs
Blog
Code Optimization
Code Quality
Command Line
Daily tips
Dashboard
Data Analysis & Manipulation
Data Engineer
Data Visualization
DataFrame
Delta Lake
DevOps
DuckDB
Environment Management
Feature Engineer
Git
Jupyter Notebook
LLM
LLM
Machine Learning
Machine Learning
Machine Learning & AI
Manage Data
MLOps
Natural Language Processing
NumPy
Pandas
Polars
PySpark
Python Tips
Python Utilities
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Automate Jupyter Notebooks with Papermill

Table of Contents

Automate Jupyter Notebooks with Papermill

papermill is a tool for parameterizing, executing, and analyzing Jupyter Notebooks.

This unlocks new use cases for notebooks, such as:

  • Creating reusable reports with variable input parameters
  • Chaining notebooks together for sequential execution
  • Integrating notebooks into automated workflows

The following example shows how to run a quarterly report notebook with different parameters.

import papermill as pm

pm.execute_notebook(
    input_path='quarterly_report.ipynb',
    output_path='Q1_2024_report.ipynb',
    parameters=dict(
        quarter="Q1",
        year=2024,
        include_forecast=True
    )
)

In this example, the execute_notebook function takes the input notebook (quarterly_report.ipynb), creates a new output notebook (Q1_2024_report.ipynb), and injects the specified parameters.

You can also run papermill from the command line using the following syntax:

papermill quarterly_report.ipynb Q1_2024_report.ipynb -p quarter Q1 -p year 2024 -p include_forecast True

By using papermill, you can automate the execution of your Jupyter Notebooks and make them more flexible and reusable.

Link to papermill.

Leave a Comment

Your email address will not be published. Required fields are marked *

0
    0
    Your Cart
    Your cart is empty
    Scroll to Top

    Work with Khuyen Tran

    Work with Khuyen Tran