importnb
import jupyter notebooks as python modules and scripts.
What it is and what it does
importnb is a Python import hook that lets you treat Jupyter notebook files (.ipynb) as importable Python modules. Instead of manually extracting code from notebooks, you can use standard Python import syntax to load a notebook's code directly. The package translates notebook JSON into executable Python line-for-line, preserving error messages and line numbers. It works with top-level await, supports pytest integration for testing notebooks, and includes a CLI to run notebooks as scripts.
The package is designed for code reuse in notebook-heavy workflows. It offers customization through parameters like lazy loading, fuzzy name matching (to handle notebooks with non-Python-compatible names), and markdown-to-docstring conversion. It has no required dependencies at runtime and supports Python 3.8, 3.9, 3.10, 3.11, and 3.12 on CPython and PyPy.
Use it for:
- Reuse analysis or utility code written in one notebook across multiple other notebooks without copy-paste
- Organize notebook-based projects by importing helper notebooks as modules from a main analysis notebook
- Write unit tests in notebooks using pytest, importing the code under test from other notebooks
- Run notebooks as command-line scripts with the importnb CLI, treating them like regular Python modules
- Build extensible systems where notebooks serve as plugins or configuration modules loaded dynamically
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
importnb lets you import Jupyter notebooks as Python modules, making notebook code reusable in other notebooks or scripts via Python's standard import system.
Yes. Low install friction, no required dependencies, active maintenance, and a permissive license make it a safe choice. Install if you work regularly with Jupyter notebooks and want to reuse code across them without manual extraction. The fuzzy finder and pytest integration add real value for notebook-heavy workflows. Not necessary if you rarely share code between notebooks or prefer exporting to .py files.
Install
importnb on PyPI
pip
pip install importnbuv
uv add importnbpoetry
poetry add importnbInstalling importnb
Before you install
Low friction: single pure-Python dependency (importlib-metadata) and no required build dependencies. Actively maintained with recent commits; repo shows ongoing activity.
License in practice
Permissive license (BSD) imposes no restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
pip install importnb
from importnb import imports
with imports("ipynb"):
pass # imports notebook files with .ipynb extension
Verify before relying
- Whether fuzzy finding performance degrades significantly with large numbers of notebooks in a directory
- Compatibility with notebooks containing complex cell dependencies or circular imports
- Whether the line-for-line JSON parser handles all edge cases in real-world notebook structures
- Real-world performance and reliability of the pytest integration for notebook-based test suites
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — importlib-metadata |
| Maintenance | actively maintained — 1,016 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 79,521/month — #14,351 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: importnb-2023.11.1-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
ipynbImports Jupyter Notebook (.ipynb) files as…
permissive · top 15,000 on PyPI
testbooktestbook lets you write unit tests for Jupyter…
permissive · top 15,000 on PyPI
myst-nbSphinx extension that parses and converts…
unclear · top 5,000 on PyPI
nbconvertnbconvert converts Jupyter notebooks (.ipynb…
permissive · top 1,000 on PyPI
mkdocs-jupyterConverts Jupyter notebooks and Python scripts…
permissive · top 15,000 on PyPI
nbsphinxnbsphinx is a Sphinx extension that parses…
permissive · top 5,000 on PyPI
session-info2Captures and displays the versions of all…
copyleft · top 5,000 on PyPI
nbsphinx-linkA Sphinx extension that lets you include…
permissive · top 15,000 on PyPI
pyprojrootFinds your project's root directory and…
permissive · top 15,000 on PyPI
pipreqs-fivetranScans Python project source files and Jupyter…
permissive · top 15,000 on PyPI