• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Programmatically replace input values in a notebook before running it

This is a tool to run notebooks with input values. When you write the notebook, these are defined in the first code cell - or a cell with a 'parameters' cell tag - 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)

If you are interested in using your parameterized Jupyter notebooks through a command line interface, have a look at nbclick.

Changes

0.6

2023-02-28

  • The parameters cell no longer needs to be the first code cell: if you add a cell tag 'parameters' to another cell, parameters will be extracted from and replaced in that cell. Capitalisation doesn't matter. (PR #27).
  • Only the parameter values are replaced: other code in the parameter cell will now be preserved unchanged (PR #19). The comment= parameter now has no effect, and it may be removed in a future version.
  • The execute= parameter for replace_definitions() is now deprecated. Please use nbclient to execute your notebook after substituting parameters.
  • nbparameterise now requires Python 3.8 or above.

More Repositories

1

pynsist

Build Windows installers for Python applications
Python
850
star
2

bash_kernel

A bash kernel for IPython
Python
651
star
3

cite2c

Citations in the Jupyter Notebook
JavaScript
313
star
4

nbopen

Open a Jupyter notebook in the best available server
Python
293
star
5

igo

(Unmaintained) Go Kernel for Jupyter
Go
123
star
6

mobilechelonian

Turtles on a notebook
JavaScript
99
star
7

bookbook

Tools to use a collection of notebooks as 'chapters'
Python
97
star
8

pyxdg

PyXDG provides Python implementations of various freedesktop.org specifications. This is the Giithub mirror.
Python
78
star
9

entrypoints

Discover and load entry points from installed packages
Python
72
star
10

astsearch

Intelligently search in Python code
Python
66
star
11

Unidecode

A python module to reduce Unicode to a 'good enough' ASCII representation (outdated Github copy)
Python
29
star
12

ubit_kernel

Jupyter kernel for the BBC micro:bit
Python
23
star
13

weatbag

Written by Everyone Altogether, The Big Adventure Game
Python
21
star
14

ZeroRPC

Simple RPC for Python programs, using ZeroMQ
Python
20
star
15

jupyter-intro-xfel-jan17

Introduction to Jupyter Notebook
Jupyter Notebook
18
star
16

astcheck

Check Python ASTs against templates
Python
17
star
17

tabipy

Display tables in IPython
Python
17
star
18

reversion

Easily update version numbers across your project
Python
16
star
19

backcall

Backwards compatible callback APIs
Python
16
star
20

py-nsis-template

Template for a Python application installer
Shell
15
star
21

jupyter_kernel_mgmt

Experimental new kernel management framework for Jupyter
Python
15
star
22

wheel2conda

Convert pure-Python wheels to conda packages (experimental)
Python
11
star
23

nbconvert-reportlab

Jupyter Notebook
11
star
24

nbexplode

Explode a notebook into a directory of files, and recombine it to a .ipynb
Python
11
star
25

requests_download

Download to a local file using requests
Python
10
star
26

flonda

Conda packages from flit information
Python
10
star
27

pygame

Mirror of pygame repo
C
10
star
28

pandawash

Magic commands to quickly & transparently clean up data
Python
9
star
29

customising-nbconvert

Talk for PyData London 2016
HTML
8
star
30

europython-2017-talk

Jupyter Notebooks for Teaching and Learning
7
star
31

pygame-flatpak-test

Flatpak packaging of pygame games (experimental)
Python
7
star
32

recombinecm

Separating & recombining Jupyter notebook storage, to version control without outputs
Python
7
star
33

pyqt-app-template

Cookiecutter template for a PyQt4 application
Python
6
star
34

hello_jupyter_proxy

A minimal example server to run with jupyter-server-proxy
Python
6
star
35

redsnail

The command line that shows you where you are
JavaScript
5
star
36

wheeldex

Indexing Python wheels
Python
5
star
37

jupyter_protocol

Experimental
Python
5
star
38

bisect-demo

Demoing git bisect
Python
5
star
39

ucb-ipython-intro

IPython intro lecture at UC Berkeley, 2 March 2015
Python
4
star
40

intreehooks

Load a PEP 517 backend from inside the source tree
Python
4
star
41

tox_appveyor

Select 32 or 64-bit Python for Tox on Appveyor
Python
4
star
42

r2_kernel

R wrapper kernel for IPython
Python
4
star
43

calcurust

A sample Jupyter kernel in Rust
Rust
3
star
44

ARE

An alternative R environment for Linux
Python
3
star
45

damnpth

Forcibly fix setuptools' .pth files
Python
3
star
46

euroscipy-2017-nbval

Nbval talk at Euroscipy 2017
Jupyter Notebook
3
star
47

Zantedeschia

Experimental ZMQ integration with asyncio
Python
2
star
48

jupyter_ssh_kernels

Python
2
star
49

hdf5-units

WIP specification for recording units in HDF5 files
2
star
50

altwidgets-prototype

JavaScript
2
star
51

importtracer

Track Python imports
Python
2
star
52

pyqt4_windows_whl

Python
2
star
53

cell2function

IPython extension to convert a cell to a function
Python
2
star
54

sqlite-glance

Inspect an SQLite database in the terminal
Rust
2
star
55

tornado_xstatic

Utilities for using XStatic in Tornado applications
Python
2
star
56

spotting-stat-claims

Fullfact hackathon - identifying statistical claims
Jupyter Notebook
1
star
57

ipython-sfpython-feb-2015

Talk about IPython for SFPython, February 2015
1
star
58

XStatic-termjs

A terminal written in Javascript, packaged for Python
JavaScript
1
star
59

flit_install_py2

Shim to install packages using flit metadata on Python 2
Python
1
star
60

deskent

Find and inspect .desktop files
Rust
1
star
61

installmod

Install a Python package using conda or pip as appropriate
Python
1
star
62

jupyter_docker_kernels

Experimental docker kernels for Jupyter
Python
1
star
63

nbhtml

Save & load Jupyter notebooks as HTML
HTML
1
star
64

cern-jupyter-presentation

Presentation about Jupyter, 10 Dec 2015 at CERN
Jupyter Notebook
1
star
65

blog

Python
1
star
66

aiokernel

Experimental asyncio-based Python kernel for IPython
Python
1
star