Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

functionize_notebook-0.0.13.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

functionize_notebook-0.0.13-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file functionize_notebook-0.0.13.tar.gz.

File metadata

  • Download URL: functionize_notebook-0.0.13.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for functionize_notebook-0.0.13.tar.gz
Algorithm Hash digest
SHA256 dde43701fe70b7f321cd725115d6638c19a537128804b89515610272aa5e758b
MD5 213af8e6231a2a82b9c355d5f523fc6c
BLAKE2b-256 78c48913ef6459cfaf66adb2ac94a34e8f68facc40b270a208b92c2f380373f5

See more details on using hashes here.

File details

Details for the file functionize_notebook-0.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for functionize_notebook-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 36cccb7cdc1b13f63fd5911e5f8d48b61c029f9ae844f4b765c243a225e4e11a
MD5 53214f775d07bd49b54a8848de711c87
BLAKE2b-256 95576e42cba4d9abefc3a7732d906fd8ba48c05f608c0981eb0522cc1ac9d1d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page