Code Monkey home page Code Monkey logo

functionize-notebook's Introduction

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.

functionize-notebook's People

Contributors

buihoangtu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.