Giter Site home page Giter Site logo

bwohlberg / py2jn Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sklam/py2nb

1.0 1.0 0.0 104 KB

py2jn is a utility for converting Python scripts into Jupyter notebooks

License: BSD 3-Clause "New" or "Revised" License

Python 85.16% Jupyter Notebook 14.84%

py2jn's Introduction

py2jn

py2jn is a utility for converting Python scripts into Jupyter Notebooks. Module-level multiline (triple quote) string literals are converted into markdown cells, and sections of code separated by such strings are converted into distinct code cells.

Related Packages

This package is a fork of sklam/py2nb, which is no longer maintained. Of the numerous forks of this original project, the only ones that appear to include significant additional development are:

  • blueogive/py2nb Adds proper packaging including tests, and syntax for specifying raw notebook cells.
  • MarcusJones/py2jnb Adds proper packaging including tests, and syntax for specifying notebook code cells. This package is available via pip.

There are also some independent packages with the same name and roughly the same goals:

Requirements

The only requirement is nbformat. Under Ubuntu Linux 18.04, this requirement can be installed by the command

  sudo apt-get install python-nbformat

or

  sudo apt-get install python3-nbformat

for Python 2 or 3 respectively. It can also be installed via pip, e.g.

  sudo -H pip install nbformat

Installation

From the package root directory do

  python setup.py install

Usage

Command line

To convert a Python script into a Jupyter notebook do

  python -m py2jn input.py output.ipynb

To execute the notebook do

  jupyter nbconvert --to=notebook --execute output.ipynb

and to convert to HTML do

  jupyter nbconvert --to=html output.ipynb

Python module

Module py2jn includes the following utility functions:

Function Description
py_string_to_notebook Convert Python script in string to notebook object
py_file_to_notebook Convert Python script file to notebook object
write_notebook Write notebook object to a file
write_notebook_to_string Write notebook object to a string
python_to_notebook Convert Python script file to notebook file

Examples

See files example.py and example.ipynb in the tests directory.

Contact

Bug reports can be submitted via the GitHub Issues interface.

License

py2jn is distributed as open-source software under a BSD 3-Clause License (see the LICENSE file for details).

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.