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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.8MB
glibcpy 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.")
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.