Skip to main content

A simple package to convert between tutobooks python files, jupyter notebooks and

Project description

tutobooks

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.

Installation

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

Overview

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:

  • invisible: do not render this block.
  • shell: execute this block while prefixing each line with !.

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.

Usage

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

Credits

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tutobooks-0.1.0.tar.gz (12.5 kB view hashes)

Uploaded Source

Built Distribution

tutobooks-0.1.0-py3-none-any.whl (12.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page