Skip to main content

A MkDocs plug-in provides a source parser for *.ipynb Jupyter notebook files, base on nbconvert.

Project description

mkdocs-nbconvert

PyPI GitHub tag (latest SemVer pre-release) workflow

A MkDocs plugin provides a source parser for *.ipynb Jupyter Notebook files, based on nbconvert.

Features

  • Converts Jupyter Notebook files (.ipynb) to Markdown during the MkDocs build process
  • Supports executing notebooks before conversion to include output results
  • Concurrent processing for faster builds with max_workers option
  • Flexible configuration for input/output directories and execution options
  • Automatic cleanup of temporary files after build

Installation

This MkDocs plugin is based on Jupyter nbconvert.

When install the plugin, jupyter and nbconvert will also be installed.

Install by pip

pip install mkdocs-nbconvert

Install from source

git clone https://github.com/tanbro/mkdocs-nbconvert.git
cd mkdocs-nbconvert
pip install .

Quick Start

Mkdocs configuration

Add the nbconvert into configuration file (mkdocs.yml)'s plugins list

plugins:
    - nbconvert

In nav section, add *.ipynb files as normal markdown files with replacing extension *.ipynb to *.md, since they're converted to markdown files in output_dir:

nav:
    - index.md
    - Notebooks:
          - notebooks/installation.md
          - notebooks/usage.md
          - notebooks/image.md
          - notebooks/matplotlib.md
    - authors.md
    - changelog.md

Warning:

converted notebooks/*.md files will be removed at the end of building.

Configuration

The plugin provides several configuration options:

  • input_dir: Directory where to scan *.ipynb files

    Either absolute or relative path. When relative, it's from mkdocs configuration file's directory.

    When omitted, default value is notebooks

  • output_dir: Export notebook files to markdown files in the directory.

    It MUST be a relative path to doc_dir

    When omitted, default value is notebooks.

  • recursive: Whether scan *.ipynb files in subdirectories recursively

    When omitted, default value is True

  • execute_enabled: Whether executing notebooks before convert. false by default

  • max_workers: Number of concurrent threads used to process notebooks. Defaults to the number of CPU cores.

  • execute_options: Options for execution:

    • execute_options.run_path: Specifies in which folder to execute the notebook. The plugin in will take input_dir as the path if not specified.

    • execute_options.kernel_name: The execution kernel. When not specified, the default Python kernel is chosen.

    • execute_options.timeout: The cell execution timeout. No timeout when not specified.

    • execute_options.write_back: Whether save executed result to the notebook file. false by default.

    • execute_options.exit_on_error: Whether exit when an error occurred. Default is true.

Options can be add to configuration file as below:

plugins:
    - nbconvert:
         input_dir: notebooks
         recursive: true
         output_dir: notebooks
         execute_enabled: true
         max_workers: 4
         execute_options:
             write_back: true
             exit_on_error: true

In the above example, the plugin recursively searches Jupyter notebook files in {{project_dir}}\notebooks, then converts them to markdown files to {{project_dir}}\docs\notebooks, where {{project_dir}}\docs is the default value of doc_dir configure. A pre-execution will be performed, and the running result will be saved to original notebook files. The conversion will be processed using 4 concurrent threads.

References

Build the Site

The project's documentation site serves as a demo of how to use it.

To build and serve the doc-site, run the following command in on a virtual environment:

pip install -e . --group docs
mkdocs serve

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

mkdocs_nbconvert-0.5.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

mkdocs_nbconvert-0.5-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_nbconvert-0.5.tar.gz.

File metadata

  • Download URL: mkdocs_nbconvert-0.5.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.0

File hashes

Hashes for mkdocs_nbconvert-0.5.tar.gz
Algorithm Hash digest
SHA256 d1f7f6bdd701f9aa1a6a80e569e3391eed8074697097776aebd1d4311caa3c90
MD5 d6d509b01ec3ee0d33b22829ef6aadf8
BLAKE2b-256 f26f483c5ceac39e4a6915d7674919030b4d8d33078e083a4a6a441b76374055

See more details on using hashes here.

File details

Details for the file mkdocs_nbconvert-0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_nbconvert-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2a64c4f4aa6fbbe58f3b1eb6a74835c2376b5bf8c6e651da4f822bc09190453c
MD5 84bd6111439604e5751d7d9a259c7300
BLAKE2b-256 0ab2d70a541be48bf777aba68541c4ad7b732e979b53cef3e24bfd80a33d78c3

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