nbconvertX

A framework for customizing NBConvert templates and building reports

https://dev.azure.com/tpaine154/jupyter/_apis/build/status/timkpaine.nbcx?branchName=masterBuild Status https://img.shields.io/azure-devops/coverage/tpaine154/jupyter/25/masterCoverage https://img.shields.io/github/issues/timkpaine/nbcx.svgGitHub issues https://img.shields.io/pypi/l/nbcx.svgPyPI https://img.shields.io/pypi/v/nbcx.svgPyPI

Templates

NBConvert’s default templates are largely designed with academic styling. This repo is a collection of templates with industrial/business reports in mind.

Getting started

You can install via:

pip install nbcx

or from source:

python setup.py install

Usage

This library exposes a variety of templates (See the gallery above), as well as a few exporters to handle customizations not possible with nbconvert exporters. Thus, we expose a number of targets (you can see these as entrypoints with nbconvert.exporters key in the setup.py file).

Here is an example usage:

jupyter nbconvert --to nbcx_pdf sample.ipynb --execute --template nbcx/templates/reports/abc.tex.j2

API Documentation

class nbcx.exporters.latex.NBCXLatexExporter(config=None, **kw)[source]

Bases: nbcx.exporters.template.TemplateOverrideMixin, nbconvert.exporters.latex.LatexExporter

export_from_notebook = 'NBCX LaTeX'
from_notebook_node(nb, resources=None, **kw)[source]

Convert a notebook from a notebook node instance.

Parameters:
  • nb (NotebookNode) – Notebook node
  • resources (dict) – Additional resources that can be accessed read/write by preprocessors and filters.
class nbcx.exporters.pdf.NBCXPDFExporter(config=None, **kw)[source]

Bases: nbcx.exporters.template.TemplateOverrideMixin, nbconvert.exporters.pdf.PDFExporter

Custom Exporter to reformat the notebook node to allow for document-level configuration from cell outputs based on tags

export_from_notebook = 'NBCX PDF Report via LaTeX'
from_notebook_node(nb, resources=None, **kw)[source]

Convert a notebook from a notebook node instance.

Parameters:
  • nb (NotebookNode) – Notebook node
  • resources (dict) – Additional resources that can be accessed read/write by preprocessors and filters.
class nbcx.exporters.template.TemplateOverrideMixin[source]

Bases: object

nbcx.utils.common.in_nbconvert[source]

helper function to check if running in nbcx context

nbcx.utils.common.nbconvert_context[source]

get context in which nbcx is running, either ‘pdf’ or ‘html’

nbcx.utils.html.grid(items_and_weights)[source]
nbcx.utils.html.h1(text, **kwargs)[source]
nbcx.utils.html.h2(text, **kwargs)[source]
nbcx.utils.html.h3(text, **kwargs)[source]
nbcx.utils.html.h4(text, **kwargs)[source]
nbcx.utils.html.h5(text, **kwargs)[source]
nbcx.utils.html.hr()[source]

horizontal rule

nbcx.utils.html.newpage()[source]

make a new page. in html, this just does a horizontal rule

nbcx.utils.html.p(text, **kwargs)[source]
nbcx.utils.html.pagenum()[source]

display a page number (latex only)

nbcx.utils.html.plot(fig)[source]
nbcx.utils.html.print(text, **kwargs)[source]

wrapper around printing

nbcx.utils.html.table(df, title='', footnote='')[source]

helper to display a table

class nbcx.tags.Tags[source]

Bases: enum.Enum

An enumeration.

CFOOT = 'nbcx_cfoot'
CHEAD = 'nbcx_chead'
FOOTER = 'nbcx_cfoot'
HEADER = 'nbcx_chead'
LFOOT = 'nbcx_lfoot'
LHEAD = 'nbcx_lhead'
NBCONVERT_IGNORE = 'nbcx_ignore'
PARAMETERS = 'parameters'
RFOOT = 'nbcx_rfoot'
RHEAD = 'nbcx_rhead'
TITLEPAGE = 'nbcx_title'