Exporters

See also

Configuration options
Configurable options for the nbconvert application
class nbconvert.exporters.Exporter(config=None, **kw)

Class containing methods that sequentially run a list of preprocessors on a NotebookNode object and then return the modified NotebookNode object and accompanying resources dict.

__init__(config=None, **kw)

Public constructor

Parameters:
  • config (Config) – User configuration instance.
  • **kw – Additional keyword arguments passed to parent __init__
from_notebook_node(nb, resources=None, **kw)

Convert a notebook from a notebook node instance.

Parameters:
  • nb (NotebookNode) – Notebook node (dict-like with attr-access)
  • resources (dict) – Additional resources that can be accessed read/write by preprocessors and filters.
  • **kw – Ignored
from_filename(filename, resources=None, **kw)

Convert a notebook from a notebook file.

Parameters:
  • filename (str) – Full filename of the notebook file to open and convert.
  • resources (dict) – Additional resources that can be accessed read/write by preprocessors and filters.
  • **kw – Ignored
from_file(file_stream, resources=None, **kw)

Convert a notebook from a notebook file.

Parameters:
  • file_stream (file-like object) – Notebook file-like object to convert.
  • resources (dict) – Additional resources that can be accessed read/write by preprocessors and filters.
  • **kw – Ignored
register_preprocessor(preprocessor, enabled=False)

Register a preprocessor. Preprocessors are classes that act upon the notebook before it is passed into the Jinja templating engine. preprocessors are also capable of passing additional information to the Jinja templating engine.

Parameters:
  • preprocessor (Preprocessor) – A dotted module name, a type, or an instance
  • enabled (bool) – Mark the preprocessor as enabled
class nbconvert.exporters.TemplateExporter(config=None, **kw)

Exports notebooks into other file formats. Uses Jinja 2 templating engine to output new formats. Inherit from this class if you are creating a new template type along with new filters/preprocessors. If the filters/ preprocessors provided by default suffice, there is no need to inherit from this class. Instead, override the template_file and file_extension traits via a config file.

  • add_anchor
  • add_prompts
  • ansi2html
  • ansi2latex
  • ascii_only
  • citation2latex
  • comment_lines
  • escape_latex
  • filter_data_type
  • get_lines
  • get_metadata
  • highlight2html
  • highlight2latex
  • html2text
  • indent
  • ipython2python
  • markdown2html
  • markdown2latex
  • markdown2rst
  • path2url
  • posix_path
  • prevent_list_blocks
  • strip_ansi
  • strip_dollars
  • strip_files_prefix
  • wrap_text
__init__(config=None, **kw)

Public constructor

Parameters:
  • config (config) – User configuration instance.
  • extra_loaders (list[of Jinja Loaders]) – ordered list of Jinja loader to find templates. Will be tried in order before the default FileSystem ones.
  • template (str (optional, kw arg)) – Template to use when exporting.
from_notebook_node(nb, resources=None, **kw)

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.
from_filename(filename, resources=None, **kw)

Convert a notebook from a notebook file.

Parameters:
  • filename (str) – Full filename of the notebook file to open and convert.
  • resources (dict) – Additional resources that can be accessed read/write by preprocessors and filters.
  • **kw – Ignored
from_file(file_stream, resources=None, **kw)

Convert a notebook from a notebook file.

Parameters:
  • file_stream (file-like object) – Notebook file-like object to convert.
  • resources (dict) – Additional resources that can be accessed read/write by preprocessors and filters.
  • **kw – Ignored
register_preprocessor(preprocessor, enabled=False)

Register a preprocessor. Preprocessors are classes that act upon the notebook before it is passed into the Jinja templating engine. preprocessors are also capable of passing additional information to the Jinja templating engine.

Parameters:
  • preprocessor (Preprocessor) – A dotted module name, a type, or an instance
  • enabled (bool) – Mark the preprocessor as enabled
register_filter(name, jinja_filter)

Register a filter. A filter is a function that accepts and acts on one string. The filters are accessible within the Jinja templating engine.

Parameters:
  • name (str) – name to give the filter in the Jinja engine
  • filter (filter) –

Specialized exporter classes

The NotebookExporter inherits directly from Exporter, while the other exporters listed here inherit either directly or indirectly from TemplateExporter.

class nbconvert.exporters.NotebookExporter(config=None, **kw)

Exports to an IPython notebook.

class nbconvert.exporters.HTMLExporter(config=None, **kw)

Exports a basic HTML document. This exporter assists with the export of HTML. Inherit from it if you are writing your own HTML template and need custom preprocessors/filters. If you don’t need custom preprocessors/ filters, just change the ‘template_file’ config option.

class nbconvert.exporters.SlidesExporter(config=None, **kw)

Exports HTML slides with reveal.js

class nbconvert.exporters.LatexExporter(config=None, **kw)

Exports to a Latex template. Inherit from this class if your template is LaTeX based and you need custom tranformers/filters. Inherit from it if you are writing your own HTML template and need custom tranformers/filters. If you don’t need custom tranformers/filters, just change the ‘template_file’ config option. Place your template in the special “/latex” subfolder of the ”../templates” folder.

class nbconvert.exporters.MarkdownExporter(config=None, **kw)

Exports to a markdown document (.md)

class nbconvert.exporters.PDFExporter(config=None, **kw)

Writer designed to write to PDF files

class nbconvert.exporters.PythonExporter(config=None, **kw)

Exports a Python code file.

class nbconvert.exporters.RSTExporter(config=None, **kw)

Exports restructured text documents.

Specialized exporter functions

These functions are essentially convenience functions that wrap the functionality of the classes documented in the previous section.

nbconvert.exporters.export_custom(nb, **kw)

Export a notebook object to custom format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_html(nb, **kw)

Export a notebook object to html format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_slides(nb, **kw)

Export a notebook object to slides format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_latex(nb, **kw)

Export a notebook object to latex format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_pdf(nb, **kw)

Export a notebook object to pdf format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_markdown(nb, **kw)

Export a notebook object to markdown format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_python(nb, **kw)

Export a notebook object to python format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_rst(nb, **kw)

Export a notebook object to rst format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_script(nb, **kw)

Export a notebook object to script format

nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple
nbconvert.exporters.export_by_name(format_name, nb, **kw)

Export a notebook object to a template type by its name. Reflection (Inspect) is used to find the template’s corresponding explicit export method defined in this module. That method is then called directly.

Parameters:format_name (str) – Name of the template style to export to.
nb : NotebookNode
The notebook to export.
config : config (optional, keyword arg)
User configuration instance.
resources : dict (optional, keyword arg)
Resources used in the conversion process.
Returns:
output : str
Jinja 2 output. This is the resulting converted notebook.
resources : dictionary
Dictionary of resources used prior to and during the conversion process.
exporter_instance : Exporter
Instance of the Exporter class used to export the document. Useful to caller because it provides a ‘file_extension’ property which specifies what extension the output should be saved as.
Return type:tuple