Skip to main content

Motivation

Suppose you want to import the contents of A.ipynb into B.ipynb.

Installation

pip install import-ipynb

How to use

Place both ipynb files in the same directory. Then, in the B.ipynb:

import import_ipynb
import A

Congratulations! You can now run any functions defined in A.ipynb from B.ipynb!

How it works

The code within import_ipynb.py defines a “notebook loader” that allows you to ‘import’ other ipynb files into your current ipynb file. This entails:

  1. load the notebook document into memory

  2. create an empty Module

  3. execute every cell in the Module namespace

Note that since every cell in the A.ipynb is executed when you import the the file, A.ipynb should only contain classes and function definitions (otherwise you’ll end up loading all variables and data into memory).

Credits

The code within import_ipynb.py comes from http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Importing%20Notebooks.html.

Riley F. Edmunds (@rileyedmunds) wrote instructions on how to use it and Lev Maximov (@axil) packaged it.

Release files for import-ipynb 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for import-ipynb 0.2.1
File Size Uploaded
import_ipynb-0.2.1.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for import-ipynb 0.2.1
File Interpreter ABI Platform
import_ipynb-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / import_ipynb-0.2.1.tar.gz

Download URL import_ipynb-0.2.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
79f831300cfcf11600657b4f310b2204e091e9169253a677f47949f39e4bba91
BLAKE2b-256 checksum
How to use checksums
b364fa165e69d20965db4faaf72ee8dd3221cd42babfcf534b1d093db9fc8aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Release files / import_ipynb-0.2.1-py3-none-any.whl

Download URL import_ipynb-0.2.1-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5fe25de484a5a14c1ceaf9fa0484f85a74e2e1386331cc3d6a005c789efdc30
BLAKE2b-256 checksum
How to use checksums
c6a923602b0aaab580985949dbefd2f37fb3dedda469c3b13e0c69088c7fc9fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2

2 release files

0.1.4

2 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page