Skip to main content

Inherit from Jupyter kernels

Project description

Jupyter Inheritance

Inherit Jupyter Kernels

You have a notebook base.ipynb with a cell

import os
from datetime import datetime

class Test:
    msg = "Hey!"

def add(x, y):
    return x + y
    
test = Test()
now = datetime.now()

that has been executed. You can create a new notebook and run the following code:

from jupyter_inheritance import inherit_from
inherit_from("base.ipynb")

assert add(1, 4) == 5
assert isinstance(test, Test)

print(test.msg)
print(now)  # same value as `now` in `base.ipynb`!
print(os.listdir("."))

The base.ipynb content is not executed from scratch in the new notebook, all the existing objects are copied directly from base.ipynb kernel. This ensures that everything stays exactly the same (e.g. timestamps, random numbers, responses from externals APIs).

You can even do mixins!

from jupyter_inheritance import inherit_from
for notebook in ("base_1.ipynb", "base_2.ipynb"):
    inherit_from(notebook)

Installation

Just the usual

pip install jupyter-inheritance

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

jupyter-inheritance-0.1.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

jupyter_inheritance-0.1.0-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

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