Re-run a notebook substituting input parameters in the first cell.
Project description
This is a tool to run notebooks with input values. When you write the notebook, these are defined in the first code cell, with regular assignments like this:
stock = 'YHOO'
days_back = 600
Nbparameterise handles finding and extracting these parameters, and replacing them with input values. You can then run the notebook with the new values. This can be used for:
Batch processing: run the same code on a list of different inputs. See examples/batch.py.
Simple user interfaces: build an input form based on the parameters, and run the notebook when the user submits the form. See examples/webapp.py for an implementation of this with an HTML form.
Nbparameterise can identify and replace numbers, strings, booleans (True/False), lists and dicts - the types which can be represented in JSON (apart from None). It’s designed to change parameter values but keep their types, although this isn’t enforced.
Extra information about the parameters, such as names to display in a user interface, can be stored in notebook metadata.
Nbparameterise is written in Python 3, but it can handle notebooks that use Python 2.
Usage:
import nbclient
import nbformat
from nbparameterise import (
extract_parameters, replace_definitions, parameter_values
)
with open("Stock display.ipynb") as f:
nb = nbformat.read(f, as_version=4)
# Get a list of Parameter objects
orig_parameters = extract_parameters(nb)
# Update one or more parameters
params = parameter_values(orig_parameters, stock='GOOG')
# Make a notebook object with these definitions
new_nb = replace_definitions(nb, params)
# Execute the notebook with the new parameters
nbclient.execute(new_nb)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nbparameterise-0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4e84385f5f54d8701c307c7b3224cdb09e0919822110c39dd5ccfee5ee03d56 |
|
MD5 | cb54af5b93e6040ddb096b449bc358b2 |
|
BLAKE2b-256 | c0d00ca7caad670f32756491e5a1c89d4850211a0240548ff907750c4d7dcf64 |