Code Monkey home page Code Monkey logo

jupyjet's Introduction

Jupyjet

Jupyjet is a IPython notebook extension to facilitate:

Practically speaking, for each notebook a python file is dynamically created:
ie - it generate python modules based of notebook content.

Usage

3 magics commands are exposed: %jet_beg, %jet and %jet_end

  • jet_beg: save all the content of the current cell and place it at the top of the file.
    It is supposed to contains imports / global variables.
    NB: Only one init is allowed and it must be the last line of the cell.

  • jet decl1 decl2 ...: save or update the declaration in the file.
    Classes, function and decorators are supported.
    Comments will be stripped.
    The file content is updated everytime the magic runs.

  • jet_end: save all the content of the current cell and place it at the bottom of the file.
    It is supposed to contain for example a ifmain block.
    NB: Only one init is allowed and it must be the last line of the cell.

Example

my_super_notebook.ipynb

Cell 1 - We declare here the header of the file

import numpy as np
pi = 3.14

%jet_beg

And save it as raw content


Cell 2 - We create a few functions

def circle_perim(r):
	return 2 * pi * r

def circle_area(r):
	return pi * r**2

%jet circle_perm circle_area

And save them


Cell 3 - in the context of the notebook, we can run some experiement
We can then use these functions normally

print circle_perim(2.)
print circle_area(2.2)

The results won't be saved into the file


The coresponding generated file is:

my_super_notebook.py

import numpy as np
pi = 3.14

# --- JET BEG --- #

def circle_perim():
    return 2 * pi * r


def circle_area():
    return pi * r ** 2


# --- JET END --- #


So this python generated module can be called from other notebooks.

NB: comments are not saved in the genrated files.

Install

Jupyjet is available on pip and compatible with both python2 and python3

pip install jupyjet
pip3 install jupyjet

Enable the extension

Here is a small guide to activate the extension.

1. Create a jupyter profile

$ ipython profile create

It will generate a default profile file at: ~/.ipython/profile_default/ipython_config.py.

2. Register Jupyjet as an extension (and other cool ones like line-profiler).

To do so add the following lines.

c.TerminalIPythonApp.extensions = [
    'jupyjet',
    'line_profiler',
]
c.InteractiveShellApp.extensions = [
    'jupyjet',
    'line_profiler',
]
3. Enjoy =)

jupyjet's People

Contributors

pelodelfuego avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.