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 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, and execute it.
new_nb = replace_definitions(nb, params)
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
File details
Details for the file nbparameterise-0.4.tar.gz
.
File metadata
- Download URL: nbparameterise-0.4.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.22.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0fcf0db7f47b2e1481a5a3eef444269e32835ca8614cde4b0e69a391a8cd681 |
|
MD5 | 4a8ae998f7a3bd0fc3bcb6b5253953d7 |
|
BLAKE2b-256 | 2a8a2ae6093d590f5f2194b7b8c84ab629e8eac9560999ff4d490ef8c3735e39 |
File details
Details for the file nbparameterise-0.4-py3-none-any.whl
.
File metadata
- Download URL: nbparameterise-0.4-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.22.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b42f338413c0c9016298440bf1ce6569b7e0aac591d3b9ceca3ccc0f795ebb2 |
|
MD5 | 138209a61c06f24a281ee90adc1e05f6 |
|
BLAKE2b-256 | 1b94a8721aa4d6d47c786d0f48eb4cd0f54b34c8305713b56e7d2988394c1400 |