Skip to content

A python package that allows importing Jupyter notebooks as python modules

License

Notifications You must be signed in to change notification settings

pitamar/jupyter-module-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jupyter notebooks module loader

Allows to import Jupyter notebooks as if there were regular python modules.

The code is based on the following example from Jupyter's documentation:
https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Importing%20Notebooks.html

Installation

pip install jupyter-module-loader

Usage

Suppose a project has the following files structure:

src/
├── main.py
└── my_notebook.ipynb

Let my_notebook.ipynb have a cell containing following code:

    def fn():
        ...

Within main.py it is possible to import my_notebook.ipynb like so:

    import jupyter_module_loader
    jupyter_module_loader.register()

    import my_notebook
    my_notebook.fn() # Calls fn() defined within the notebook above

You may limit the cells that are imported by assigning tags to those cells you want to load and call:

jupyter_module_loader.register(tags=[<a list of tags that work as markers for cells that are to be imported>])

About

A python package that allows importing Jupyter notebooks as python modules

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published