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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file tutobooks-0.1.0.tar.gz.

File metadata

  • Download URL: tutobooks-0.1.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for tutobooks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9360ebe0a1ae3c033cb5830cd5a3182a3c5ec227477dffcc782b9a57cd2accab
MD5 e2078b91d97c9904e2be6566f08c013c
BLAKE2b-256 035a645a2b025a2fa56ef8cbe2619f49302c76c0ae0e546218415e95215cbd71

See more details on using hashes here.

File details

Details for the file tutobooks-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tutobooks-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for tutobooks-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa12910901f6242fc88889a6693a828bccaee7b07ea3744eaa5d27f022052de2
MD5 324b7e72713eaeb0f7529cabd6996fd8
BLAKE2b-256 d28e0bdf9e0ebe520651a1858035779bc2122be336f1b16b21af23a86fb231ab

See more details on using hashes here.

Supported by

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