run notebook like a function
Project description
functionize-notebook
functionize-notebook
allows you to wrap jupyter-notebook
and use it like a function. It
allows passing input and output. It is not multi-thread safe.
Installation
$ pip install -U functionize-notebook
Start
The main function used in pandasql is NotebookWrapper
. NotebookWrapper
expect 3 parameters
- a path to the notebook.
- a list of input params' names (these params will be used in the notebook).
- a list of output params' names (these params must exist in the notebook).
- (optional) which tag indicating input. Default "input".
Notebook
If you want to use input, you must create a cell dedicated to input. In which, only assignment happens. Any calculation in this cell may lead to unexpected results. This cell also need to have tag input
or the value you put in inputTag
Run the notebook
Example: you want to pass a
, b
as input and want sum
back.
calculateSum = NotebookWrapper("./sum.ipynb", ["a", "b"], "sum")
You can now run this by method run
sum = calculateSum.run(5, 10)
or just call it like a function
sum = calculateSum(5, 10)
You can also pass input as named params (you don't have to specify these params beforehand while create the object). These params will overide the previous.
sum = calculateSum(5, 10, a = 8, c = 9)
This will overide value of a. Now a = 8. Variable c = 9 is also injected to notebook.
You can also pass other datatype. However, Any modifications made by notebook won't be reflected on the object. You can still return the object to get the modifications.
Export notebook
Example: You want to rerun notebook with different inputs.
for i in range(100):
calculateSum.export(f"outputNb-{str(i)}.ipynb", 5 * i, 10 + i)
export
return the same result with running normally.
More information and code samples available in the examples folder.
Project details
Release history Release notifications | RSS feed
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 functionize_notebook-0.0.11.tar.gz
.
File metadata
- Download URL: functionize_notebook-0.0.11.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee310a46aeaf21016a47832d17c97bd0ff1d661e951a26b035efb343541355d |
|
MD5 | 35aaedcc8b9d41a6329321eefd81df77 |
|
BLAKE2b-256 | a7eff10ea12bb3aa32c4a3f0ecd32fbb2b1bc54ad175c7346aa2121a24f4a6ca |
File details
Details for the file functionize_notebook-0.0.11-py3-none-any.whl
.
File metadata
- Download URL: functionize_notebook-0.0.11-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19a33606360784eb816722def4998a3b8b3f62fe6785434b377879ad943e3bc8 |
|
MD5 | a7d932e155c9f3d4395fe8e23f82f1e3 |
|
BLAKE2b-256 | 464881a429bf4a3324debf41184f0948c74e609a499ebc74ffd6da894351e154 |