Registry / workflow / nbparameterise

nbparameterise

JSON →
library0.6.1pypypi✓ verified 87d ago

nbparameterise is a Python library (current version 0.6.1) designed to re-run Jupyter notebooks while substituting input parameters in the first cell. It's often used for automating notebook execution with different configurations or datasets, making it a valuable tool for reproducible research and data pipeline orchestration. The project maintains a steady release cadence, typically driven by bug fixes and minor feature enhancements.

pip install nbparameterise
INSTALL
IMPORT
SIG · NBPARAMETERISE
N
nbparameterise
workflowpythonv0.6.1
Install
3.1s avg
Import
—
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.8MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 3.1s · import 0.000s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Parameter
✓ from nbparameterise import Parameter
✗ from nbparameterise import parameterise
extract_parameters
✓ from nbparameterise import extract_parameters
✗ from nbparameterise import parameterise
parameter_values
✓ from nbparameterise import parameter_values
✗ from nbparameterise import parameterise

This quickstart demonstrates how to programmatically define, parameterise, and execute a Jupyter notebook using `nbparameterise`. It creates a dummy notebook, overrides its initial parameters, executes it, and then prints the output, finally cleaning up generated files. Ensure `ipykernel` is installed for successful execution.

import os from nbparameterise import parameterise, execute_notebook import nbformat # 1. Define the input notebook content (as a string) that includes parameters input_notebook_content = """ { "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Parameters\n", "x = 10\n", "y = 'hello'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f'Original x: {x}')\n", "print(f'Original y: {y}')\n", "result = x * 2\n", "print(f'Result: {result}')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.x.x" } }, "nbformat": 4, "nbformat_minor": 4 } """ # Define file paths input_path = "quickstart_input.ipynb" output_path = "quickstart_output.ipynb" # Save the dummy input notebook file with open(input_path, "w") as f: f.write(input_notebook_content) print(f"Created input notebook: {input_path}") try: # Load the notebook object with open(input_path) as f: nb = nbformat.read(f, as_version=4) # Extract current parameters and define new values to override them params = parameterise.extract_parameters(nb) new_params = parameterise.parameter_values(params, x=25, y="world!") # Override x and y parameterised_nb = parameterise.replace_definitions(nb, new_params) # Execute the modified notebook and save the output # Requires 'ipykernel' to be installed in the environment. execute_notebook(parameterised_nb, output_path) print(f"Notebook executed and saved to {output_path}") # Optionally, verify the output from the executed notebook with open(output_path) as f: output_nb = nbformat.read(f, as_version=4) print("\n--- Output Notebook Cells ---") for cell in output_nb.cells: if cell.cell_type == 'code': for output in cell.outputs: if output.output_type == 'stream': print(output.text.strip()) except Exception as e: print(f"Error during quickstart execution: {e}") print("Hint: Ensure 'ipykernel' is installed (`pip install ipykernel`) for notebook execution.") finally: # Clean up generated files if os.path.exists(input_path): os.remove(input_path) if os.path.exists(output_path): os.remove(output_path) print("\nCleaned up generated files.")
Debug
Known issues
breakingDropped Python 3.7 support.
fix
Upgrade your Python environment to 3.8 or newer to use nbparameterise versions 0.6.0 and above.
affects: >=0.6.0
deprecatedThe direct function `run_notebook_dir` was removed and replaced by methods within the `parameterise` object.
fix
Update your code to use `from nbparameterise import parameterise, execute_notebook` and then call `execute_notebook(notebook, path)` instead.
affects: <=0.2.x
gotchaParameters are only reliably recognized if defined in the first *code* cell of the notebook.
fix
Ensure all variables intended as parameters are assigned in the very first executable code cell. While not strictly required by the library, adding `# Parameters` as a comment in that cell helps for readability and tool recognition.
affects: all
gotchaNotebook execution requires an active Jupyter kernel in the environment.
fix
Ensure 'ipykernel' is installed (`pip install ipykernel`) in the Python environment where `nbparameterise` is being run. If using virtual environments or different kernels, verify the correct kernel is available and registered.
affects: all
Upgrade
Version history
0.6.1latest on PyPI · released May 15, 2024
Audit
Dependencies
nbformatrequiredRequired for reading and writing Jupyter notebook files.
ipykernelrequiredRequired for actual execution of notebook cells via a Jupyter kernel.
traitletsrequiredA core dependency within the Jupyter ecosystem, used for configuration.
Agent activity
29 hits · last 30 days
node
26
OpenAI (training)
1
Resources
nbparameterise — pip install nbparameterise · libregistry