Skip to main content

A tool to split a template Jupyter notebook into a solution and a task version.

Project description

nbtemplater

A utility to convert a template Jupyter notebook into separate solution and task versions based on simple directives.

# this converts template.ipynb to template_solution.ipynb and template_task.ipynb
nbtemplater template.ipynb

In addition to being able to convert a single file, nbtemplater.py can also be used to (recursively) convert all notebook files in a given directory like:

# this converts all .ipynb files in notebook-folders/
nbtemplater notebook-folders/

# this recursively converts all .ipynb files in notebook-folders/
# so e.g. notebook-folders/bar/template.ipynb
nbtemplater -r notebook-folders/

Installation

For easy installation, you can install nbtemplater directly here from PyPI. So you can install it using:

pip install nbtemplater

Manual installation

If you prefer not to install from pip you can get the source code at the GitHub repository, where you can also find a requirements.txt file, listing all dependencies.

Sample conversion

If the following text is included in any part or cell of the template notebook, it is split up into the appropriate versions:

Template

# This is some basic content
%%IF_SOL%%
any text before the next directive is
only going to be visible in the solution
version of this notebook
%%ELSE%%
this **optional** section is going to be copied
into the task version
%%END%%

Solution

# This is some basic content
any text before the next directive is
only going to be visible in the solution
version of this notebook

Task

# This is some basic content
this **optional** section is going to be copied
into the task version

Help text

Usage: nbtemplater [OPTIONS] [PATHS]...

  Convert PATHS.

  PATHS is a list of directories or notebook files to convert to solution
  and task files.

Options:
  -r, --recurse           Whether to recursively go through folders  [default:
                          False]

  -f, --force             Whether to overwrite an already existing file
                          [default: False]

  -q, --quiet             Disable output during conversion  [default: False]
  -p, --pattern TEXT      The pattern to search for in folders  [default:
                          *.ipynb]

  --solution-suffix TEXT  The file suffix to be used for the generated
                          solution file  [default: solution]

  --task-suffix TEXT      The file suffix to be used for the generated task
                          file  [default: student]

  --start-solution TEXT   The start of a solution block  [default: %%IF_SOL%%]
  --else-task TEXT        The start of the optional task block  [default:
                          %%ELSE%%]

  --end-if TEXT           The end of a solution/task if block  [default:
                          %%FI%%]

  -h, --help              Show this message and exit.

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

nbtemplater-0.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

nbtemplater-0.1.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file nbtemplater-0.1.2.tar.gz.

File metadata

  • Download URL: nbtemplater-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for nbtemplater-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4ea83cd473f0df3725feb390d2b72a77ed3c798c29ba53f3bd698d92fbfd8228
MD5 c32629f51e49adc5cf64e65471fc8d5a
BLAKE2b-256 0766cfaed64558d177f6bb77b8aa86ea24c65a1593b8a4b2e1e16ac3605706eb

See more details on using hashes here.

File details

Details for the file nbtemplater-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nbtemplater-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for nbtemplater-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c95e512de9849b626c9eff602f0c3f563ad7b315363597214322997a814d6b45
MD5 700e4f36b402537f6b0454c5b8c026bd
BLAKE2b-256 60f969ea102002fead2ef0ae726830b52d721f1c758dac0ed10f3a06db552c1f

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