Skip to main content

A framework for customizing NBConvert templates and building reports

Project description

nbprint nbprint

A framework for building print media with nbconvert.

Build Status Coverage GitHub issues License

Background

Jupyter Notebooks are widely used for reports via nbconvert, but most development work has been on enabling building interactive websites. The goal of nbprint is to focus on print-oriented workflows, e.g. PDF, by leveraging new developments in nbconvert and the pagedjs print-oriented layout library.

For a deeper dive, see the documentation.

Quickstart

nbprint provides an nbconvert template and a configuration framework. The simplest example can be run with defaults by calling the nbprint executable on an existing notebook:

nbprint examples/basic.ipynb

This CLI supports configuration-driven customization with hydra syntax:

nbprint examples/basic.ipynb +nbprint.name=test ++nbprint.outputs.target=pdf

# First cell is papermill-style parameters
nbprint examples/parameters.ipynb +nbprint.parameters.a=test

# Overlay a config group, e.g. title and table of contents
nbprint examples/basic.ipynb nbprint/content/frontmatter=nbprint/title_toc
graph TB
    subgraph author["authoring"]
        nb("notebook<br>(.ipynb)")
        yaml[/"YAML config<br>(hydra)"/]
    end

    subgraph build["build time — Python"]
        nbc{"nbconvert"}
        nbct[/"nbprint template<br>(Jinja2)"/]
        html@{ shape: doc, label: "standalone html<br>+ embedded JS/CSS" }
    end

    subgraph browser["render time — browser"]
        direction TB
        init["1 · initialize<br>decode images"]
        proc["2 · process<br>reparent DOM · hoist styles"]
        pre["3 · preprocess<br>measure · scale · split"]
        esm["4 · cell render()<br>await trackRender barrier"]
        pjs[/"5 · paged.js<br>paginate"/]
        post["6 · postvalidate<br>drop blanks · warn overflow"]
    end

    out@{ shape: doc, label: "final output<br>(html · pdf via webpdf)" }

    nb e1@--> nbc
    yaml --> nbc
    nbct --> nbc
    e1@{animate: true}

    nbc e2@--> html
    e2@{animate: true}

    html --> init
    init --> proc --> pre --> esm --> pjs --> post

    post e3@--> out
    e3@{animate: true}

    classDef browserPhase fill:#eef,stroke:#557,color:#000
    class init,proc,pre,esm,pjs,post browserPhase

nbprint splits work across three stages. Authoring happens in the notebook (plus optional YAML overrides via hydra). At build time, nbconvert runs the nbprint Jinja2 template to emit a single self-contained HTML file with all JS, CSS, and data embedded. At render time, the browser does the heavy lifting: reparenting the DOM by parent-id, hoisting global styles, running a preprocessing pass that measures and scales oversized content, awaiting every cell's render() function through a lifecycle barrier so pagination only starts after the DOM is stable, then handing off to paged.js for layout, and finally running a postvalidation pass that drops blank pages and surfaces overflow warnings. PDF output is produced by rendering the same HTML with nbconvert --to webpdf (headless Chromium); there is no separate PDF codepath.

For more information, see the architecture documentation.

Configuration

See the configuration framework documentation for more information on building pure YAML-based report workflows with hydra.

Installation

Install with pip:

pip install nbprint

Install with conda

conda install nbprint -c conda-forge

Development

Warning: This project is under active development, so all APIs are subject to change!

License

This software is licensed under the Apache 2.0 license. See the LICENSE file for details.

[!NOTE] This library was generated using copier from the Base Python Project Template repository.

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

nbprint-0.12.0.tar.gz (47.6 MB view details)

Uploaded Source

Built Distribution

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

nbprint-0.12.0-py3-none-any.whl (4.1 MB view details)

Uploaded Python 3

File details

Details for the file nbprint-0.12.0.tar.gz.

File metadata

  • Download URL: nbprint-0.12.0.tar.gz
  • Upload date:
  • Size: 47.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for nbprint-0.12.0.tar.gz
Algorithm Hash digest
SHA256 2707b83ea7a8105a19e3da2daa5379fcd2f8ab40c26786e0dc330f03702e64bc
MD5 c6ef7b404432ed330c051cb8ce1031ef
BLAKE2b-256 2d6ee3de7a24cb22f49022d4d19c4b4edbbe3394d61717611eca0f89499994fe

See more details on using hashes here.

File details

Details for the file nbprint-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: nbprint-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for nbprint-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aefe969aa927ad9094dfef7800f1af841f8d2d6f30f7f6927c8f4decec95c332
MD5 200c0c4ead683d715169371663dba38d
BLAKE2b-256 6a07917886b66bcb8bf7941b34e253df0fdbf7cfc3202b2feb1f1898b09cc73a

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