• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    Jupyter Notebook
  • License
    BSD 3-Clause "New...
  • Created about 8 years ago
  • Updated 7 months 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,302
star
2

ipyparallel

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

xkcd-font

The xkcd font
Python
1,113
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
646
star
6

traitlets

A lightweight Traits like module
Python
617
star
7

pickleshare

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

ipython-website

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

ipython-doc

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

rlipython

Readline Interface for IPython 5.4+
Python
32
star
11

disp

Providing default representations of common objects in Python land
Jupyter Notebook
20
star
12

matplotlib-inline

Inline Matplotlib backend for Jupyter
Jupyter Notebook
19
star
13

salt-states-nbviewer

Salt States for nbviewer
Scheme
19
star
14

front-to-back

Talk about IPython frontends and backends for PyData SV 2014
Jupyter Notebook
18
star
15

talks

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

marketing

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

ipython_genutils

Vestigial IPython utilities: DO NOT USE
Python
11
star
18

ipython-ansible-jenkins

[Deprecated] Ansible playbook for our Jenkins server
10
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
10
star
20

comm

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

paper-notebook2013

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

mozfest2014

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

sloan-2013-reports

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

usersurveys

Materials for and results from user surveys
Python
3
star
25

.github

1
star