Skip to content
forked from sklam/py2nb

py2jn is a utility for converting Python scripts into Jupyter notebooks

License

Notifications You must be signed in to change notification settings

bwohlberg/py2jn

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

About

py2jn is a utility for converting Python scripts into Jupyter notebooks

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 85.2%
  • Jupyter Notebook 14.8%