JPConvert
JPConvert is a preprocessor for Jupyter Notebooks. It may be used to split up Jupyter Notebooks based on macros, automatically set options, embed images and remove unnecessary metadata.
Quick Start
Install JPConvert:
pip install jpconvert
Imagine two code cells inside your notebook:
#jp-solution
a = a + 1
#jp-practice
a = ...
If you call JPConvert with the --practice option, the first cell is removed and the second cell is kept:
a = ...
If you call JPConvert with the --solution option, the first cell is kept and the second cell is removed:
a = a + 1
Setup
The preferred way to use JPConvert is in a virtual environment:
python -m venv venv
source venv/bin/activate
Use pip to download and install JPConvert. JPConvert requires requests and python-magic to embed images via HTTP.
Both packages are installed automatically by pip.
pip install jpconvert
Run JPConvert as a Python module:
python -m jpconvert <input> [<output>] [<options>]
Usage Guide
Macros and Output Types
JPConvert provides several macros to mark cells for a specific task. Only code cells with the macro matching the output options are kept.
| cli option | description |
|---|---|
--practice / -p |
keep cells containing #jp-practice |
--teaching / -t |
keep cells containing #jp-teaching |
--solution / -s |
keep cells containing #jp-solution |
Multiple macros can be used per cell. Macros themselves are removed from the code cells.
Instead of # you can also use --. The macros without any prefix can also be added as tags to individual cells.
It is also possible to remove any cells without macros. Add --remove-without-macros to the command line parameters
to activate this behavior.
Empty Cells, Empty Lines, Trailing Spaces
JPConvert automatically removes
- trailing spaces from lines,
- empty lines from the end of cells and
- empty cells.
This behavior can be disabled using the command line parameters
--no-strip-lines,--keep-trailingand--keep-empty.
Readonly and Undeletable
JPConvert automatically adds readonly and undeletable flags to any cells that do not contain #jp-practice. If you
want to protect the latter from writing as well, add #jp-readonly or use #jp-practice-ro. Users may undo these
changes, but at least they cannot accidentally delete or modify cells.
To disable this behavior, the command line parameters --no-force-readonly and --no-set-undeletable can be used.
Table of Contents
A table of contents is automatically inserted into all cells that contain the macro #jp-toc. The entries are
automatically generated from headlines (lines starting with one or multiple #) in markdown cells. Each entry consists
of the title and a reference that leads directly to the anchor tag of the heading.
Up to two conditionals can be added to control the table's depth. It uses the level of the heading (number of #) for
filtering. The following example shows how to create a table of contents from level 2 to 5.
#jp-toc>=2<6
Embedding Images
Images can be embedded in markdown cells via the Jupyter user interface. JPConvert automatically embeds linked files
from both local disk and HTTP(S) sources, which simplifies notebook editing. Supported file types are png, jpg and
svg.
JPConvert also embeds files that are displayed using HTML tags. These provide the ability to scale graphics as desired, while in markdown the size is determined only by the resolution.
Add the command line parameter --no-embed-images to disable this behavior.
Stripping Output
execution_count is set to None and output is set to an empty array for each individual code cell. (Which is
basically the functionality of nbstripout when called without any additional parameters.)
Add the command line parameter --keep-output to disable this behavior.
Metadata
Release files for jpconvert 0.3.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jpconvert-0.3.19.tar.gz | 14.2 kB | Without provenance | Details for jpconvert-0.3.19.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jpconvert-0.3.19-py3-none-any.whl | Python 3 | none | any | Details for jpconvert-0.3.19-py3-none-any.whl |
Total release size: 31.2 kB
Release files / jpconvert-0.3.19.tar.gz
| Download URL | jpconvert-0.3.19.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37bfe809da17217d75a628e0b2e059c0b10d1844ce180ebe513830c437739abc
|
|
BLAKE2b-256 checksum How to use checksums |
dbe5fe476314806914baf0c2c5921c364e430e79371c8c633ce7222d0bb524a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / jpconvert-0.3.19-py3-none-any.whl
| Download URL | jpconvert-0.3.19-py3-none-any.whl |
|---|---|
| Size | 17.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27e3e3221506f69958394abd32ee6ddefc3ae870b4213c01692be869853949e6
|
|
BLAKE2b-256 checksum How to use checksums |
5f6c8042f60d186261fb4940a11c8a8ffcde706dbcfab293d55fd70715c88902
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for jpconvert 0.3.19
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.