• Stars
    star
    238
  • Rank 163,574 (Top 4 %)
  • Language
    Jupyter Notebook
  • License
    BSD 3-Clause "New...
  • Created over 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Package / Module importer for importing code from Jupyter Notebook files (.ipynb)

ipynb

Build Status

A python package providing an easy way to explicitly import Jupyter Notebooks files (.ipynb) the same way you would import regular .py files.

Installation

You can install ipynb with:

pip install ipynb

Importing a notebook

Full import

You can do a 'full' import - this has the same semantics of importing a .py file. All the code in the .ipynb file is executed, and classes/functions/variables in the top level are available for use.

If you have a notebook file named server.ipynb, you can import it via:

import ipynb.fs.full.server

You can use the from ... import .. too.

from ipynb.fs.full.server import X, Y, X

Definitions only import

Sometimes your notebook has been used as a way to run an analysis or other computation, and you only want to import the functions / classes defined in it - and not the extra statements you have in there. This can be accomplished via ipynb.fs.defs.

If you have a notebook file named server.ipynb, and do:

import ipynb.fs.defs.server

It'll only execute and make available the following parts of the code in server.ipynb:

  • class definitions
  • def function definitions
  • import statements
  • Assignment statements where the variables being assigned to are ALL_CAPS. These are assumed to be constants.

This skips most computational work and brings in your definitions only, making it easy to reuse functions / classes across similar analyses.

Relative Imports

You can also easily do relative imports, both for full notebooks or for definitions only. This works inside notebooks too.

If you have a notebook called notebook1.ipynb in the same dir as your current notebook, you can import it with:

import ipynb.fs  # Boilerplate required

# Do a full import
from .full.notebook1 import foo

# Do a definitions-only import
from .defs.notebook1 import bar

This works transitively nicely - other code can import your notebook that's using relative imports and it'll all work well.

More Repositories

1

ipython

Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
Python
16,143
star
2

ipyparallel

IPython Parallel: Interactive Parallel Computing in Python
Jupyter Notebook
2,552
star
3

xkcd-font

The xkcd font
Python
1,027
star
4

ipython-in-depth

IPython and Jupyter in-depth Tutorial, first presented at PyCon 2012
Jupyter Notebook
928
star
5

ipykernel

IPython Kernel for Jupyter
Python
614
star
6

traitlets

A lightweight Traits like module
Python
602
star
7

pickleshare

File system based database that uses python pickles
Python
69
star
8

ipython-website

IPython website sources. Any fixes to the website should be done on this repository.
HTML
48
star
9

ipython-doc

Old builds of all the documentation for IPython's various releases, plus current development tree.
HTML
36
star
10

rlipython

Readline Interface for IPython 5.4+
Python
31
star
11

salt-states-nbviewer

Salt States for nbviewer
Scheme
19
star
12

disp

Providing default representations of common objects in Python land
Jupyter Notebook
18
star
13

front-to-back

Talk about IPython frontends and backends for PyData SV 2014
Jupyter Notebook
17
star
14

talks

Talks and demonstration notebooks about IPython, to be used by anyone (all materials CC-BY licensed)
Python
16
star
15

matplotlib-inline

Inline Matplotlib backend for Jupyter
Python
15
star
16

marketing

Marketing materials for IPython: logos, banners, stickers, etc.
Jupyter Notebook
12
star
17

ipython_genutils

Vestigial IPython utilities: DO NOT USE
Python
10
star
18

ipython-ansible-jenkins

[Deprecated] Ansible playbook for our Jenkins server
9
star
19

ipython.github.com

Auto-generated sphinx version of the IPython website. Since this is an auto-generated directory, do *not* submit pull requests against this repository. The actual sources are in the ipython-website repository.
HTML
9
star
20

comm

Python Comm implementation for the Jupyter kernel protocol
Python
8
star
21

paper-notebook2013

A paper about the IPython Notebook written in 2013
7
star
22

mozfest2014

Introduction to the IPython Notebook at MozFest 2014
Shell
4
star
23

sloan-2013-reports

Progress reports for the Sloan 2013-14 grant.
Python
4
star
24

usersurveys

Materials for and results from user surveys
Python
2
star