A simple package to convert between tutobooks python files, jupyter notebooks and
APACHE-2.0 License
Note: All code credit to Francois Chollet, I simply bundled this into a pip package because I wanted to use it for more than keras.io
Taken from keras-io/scripts.
You can install from GitHub or PyPi:
pip install tutobooks
or
pip install git+https://github.com/lukewood/tutobooks
or
git clone https://github.com/lukewood/tutoboks
cd tutobooks
python setup.py develop
A tutobook is a tutorial available simultaneously as a notebook, as a Python script, and as a nicely rendered webpage.
Its source-of-truth (for manual edition and version control) is
its Python script form, but you can also create one by starting
from a notebook and converting it with the command nb2py
.
Text cells are stored in markdown-formatted comment blocks. the first line (starting with " * 3) may optionally contain a special annotation, one of:
!
.The script form should start with a header with the following fields:
Title:
Author: (could be `Authors`: as well, and may contain markdown links)
Date created: (date in yyyy/mm/dd format)
Last modified: (date in yyyy/mm/dd format)
Description: (one-line text description)
You would typically start from an existing notebook.
Save it to disk (let's say as path_to_your_nb.ipynb
).
Then run:
tutobooks nb2py path_to_your_nb.ipynb your_example.py
This will create the file your_example.py
. Open it,
fill in the headers, and generally edit it so that it looks nice.
You can then preview what it looks like when converted back again to ipynb by running:
python tutobooks py2nb your_example.py preview.ipynb
Open the generated preview.ipynb
and make sure it looks like what
you expect. If not, keep editing your_example.py
until it does.
Conversion to markdown:
tutobooks nb2md mypath.ipynb mypath.md
Conversion to python:
tutobooks nb2py mypath.ipynb mypath.py
Conversion to markdown from python:
tutobooks py2md mypath.py mypath.md
Francois Chollet wrote almost all of the code for this (see keras.io repo), I just packaged it up into a PyPi package with proper CLI parsing and some tweaking to make the usage more generic.