Top Related Projects
Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
📚 Parameterize, execute, and analyze notebooks
Create delightful software with Jupyter Notebooks
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
Create beautiful, publication-quality books and documents from computational content.
Voilà turns Jupyter notebooks into standalone web applications
Quick Overview
nbconvert is a powerful tool for converting Jupyter Notebooks to various output formats. It allows users to transform their notebooks into static formats like HTML, PDF, and LaTeX, as well as executable formats like Python scripts. This project is an essential part of the Jupyter ecosystem, enabling seamless sharing and publication of notebook content.
Pros
- Supports a wide range of output formats, including HTML, LaTeX, PDF, Markdown, and more
- Highly customizable through templates and configuration options
- Integrates well with other Jupyter tools and can be used programmatically
- Actively maintained and part of the larger Jupyter project ecosystem
Cons
- Can be complex to set up for certain output formats (e.g., PDF conversion requires LaTeX installation)
- Performance can be slow for large notebooks or when converting multiple notebooks
- Some advanced features may require understanding of templating systems and command-line usage
- Limited support for interactive elements when converting to static formats
Code Examples
- Basic conversion of a notebook to HTML:
from nbconvert import HTMLExporter
# Create an HTMLExporter instance
html_exporter = HTMLExporter()
# Convert the notebook
output, resources = html_exporter.from_filename("my_notebook.ipynb")
# Write the output to a file
with open("output.html", "w", encoding="utf-8") as f:
f.write(output)
- Converting a notebook to a Python script:
from nbconvert import PythonExporter
# Create a PythonExporter instance
python_exporter = PythonExporter()
# Convert the notebook
output, resources = python_exporter.from_filename("my_notebook.ipynb")
# Write the output to a file
with open("output.py", "w", encoding="utf-8") as f:
f.write(output)
- Using nbconvert from the command line:
# Convert to HTML
jupyter nbconvert --to html my_notebook.ipynb
# Convert to PDF
jupyter nbconvert --to pdf my_notebook.ipynb
# Convert to Python script
jupyter nbconvert --to python my_notebook.ipynb
Getting Started
To get started with nbconvert, follow these steps:
- Install nbconvert:
pip install nbconvert
-
For PDF conversion, ensure you have a LaTeX distribution installed (e.g., TeX Live, MiKTeX).
-
Convert a notebook using the command line:
jupyter nbconvert --to html path/to/your/notebook.ipynb
- Or use nbconvert programmatically in Python:
from nbconvert import HTMLExporter
html_exporter = HTMLExporter()
output, resources = html_exporter.from_filename("path/to/your/notebook.ipynb")
For more advanced usage and customization options, refer to the official nbconvert documentation.
Competitor Comparisons
Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
Pros of IPython
- More comprehensive interactive computing environment
- Richer set of features for interactive Python development
- Deeper integration with shell environments and system-level operations
Cons of IPython
- Larger codebase and potentially more complex to contribute to
- May include features not needed for simple notebook conversion tasks
- Slower development cycle due to broader scope
Code Comparison
IPython (interactive shell):
In [1]: %timeit [i**2 for i in range(1000)]
339 µs ± 5.95 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
nbconvert (command-line usage):
$ jupyter nbconvert --to python notebook.ipynb
Summary
IPython provides a full-featured interactive computing environment, while nbconvert focuses specifically on notebook conversion. IPython offers more extensive features for interactive Python development and system integration, but this comes with increased complexity and a larger codebase. nbconvert, being more specialized, provides a streamlined solution for converting Jupyter notebooks to various formats. The choice between the two depends on whether you need a comprehensive interactive environment (IPython) or a dedicated notebook conversion tool (nbconvert).
📚 Parameterize, execute, and analyze notebooks
Pros of Papermill
- Designed for parameterizing and executing notebooks
- Supports remote execution and scheduling
- Allows for easy integration with workflow management systems
Cons of Papermill
- More focused on execution than conversion to other formats
- Less flexibility in output formats compared to nbconvert
- May require additional setup for complex workflows
Code Comparison
Papermill execution:
import papermill as pm
pm.execute_notebook(
'input.ipynb',
'output.ipynb',
parameters={'alpha': 0.6, 'ratio': 0.1}
)
nbconvert conversion:
from nbconvert import HTMLExporter
import nbformat
with open("notebook.ipynb") as f:
nb = nbformat.read(f, as_version=4)
html_exporter = HTMLExporter()
(body, resources) = html_exporter.from_notebook_node(nb)
Key Differences
- Papermill focuses on parameterized execution of notebooks
- nbconvert specializes in converting notebooks to various formats
- Papermill is better suited for automation and batch processing
- nbconvert offers more options for customizing output appearance
Use Cases
- Papermill: Automated reporting, batch processing, and workflow integration
- nbconvert: Converting notebooks to presentations, reports, or other document formats
Community and Ecosystem
Both projects have active communities and are part of the broader Jupyter ecosystem, with nbconvert being more closely tied to the core Jupyter project.
Create delightful software with Jupyter Notebooks
Pros of nbdev
- Designed for literate programming, allowing development of entire Python libraries in notebooks
- Includes tools for automated documentation generation and testing
- Supports two-way sync between notebooks and source files
Cons of nbdev
- Steeper learning curve due to additional features and conventions
- More opinionated workflow that may not suit all development styles
- Limited to Python projects, while nbconvert supports multiple languages
Code comparison
nbdev:
# %nbdev_export
def my_function(x):
"""This function will be exported"""
return x * 2
nbconvert:
def my_function(x):
"""This function will be converted"""
return x * 2
nbdev uses special comments to control export behavior, while nbconvert typically converts all cells by default.
Key differences
- nbdev focuses on library development, while nbconvert is primarily for converting notebooks to other formats
- nbdev integrates with git for version control, whereas nbconvert is format-conversion focused
- nbdev provides a more comprehensive development ecosystem, including CI/CD integration
Both tools serve different purposes within the Jupyter ecosystem, with nbdev offering a more specialized workflow for Python library development, and nbconvert providing broader format conversion capabilities.
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
Pros of Jupytext
- Supports bidirectional conversion between notebooks and various text formats (e.g., Markdown, R Markdown, Python scripts)
- Enables version control of notebooks in plain text formats
- Allows for easier collaboration and code review of notebook content
Cons of Jupytext
- Requires additional setup and configuration compared to nbconvert
- May not preserve all notebook metadata and cell outputs in text formats
- Limited export options compared to nbconvert's wide range of output formats
Code Comparison
nbconvert:
jupyter nbconvert --to html notebook.ipynb
Jupytext:
jupytext --to py:percent notebook.ipynb
Summary
nbconvert is a more established tool with broader output format support, while Jupytext focuses on seamless conversion between notebooks and text-based formats. Jupytext excels in version control and collaboration scenarios, but may require additional setup. nbconvert offers a simpler conversion process with more output options, making it better suited for generating various document types from notebooks. The choice between the two depends on specific workflow requirements and version control needs.
Create beautiful, publication-quality books and documents from computational content.
Pros of jupyter-book
- Provides a complete framework for creating structured, multi-page documents
- Offers enhanced customization options for book-like outputs
- Supports advanced features like cross-references and citations
Cons of jupyter-book
- Steeper learning curve due to additional configuration options
- May be overkill for simple notebook conversion tasks
- Requires more setup and dependencies compared to nbconvert
Code comparison
nbconvert:
jupyter nbconvert --to html notebook.ipynb
jupyter-book:
# _config.yml
title: My Jupyter Book
author: Your Name
logo: logo.png
# _toc.yml
format: jb-book
root: index
chapters:
- file: chapter1
- file: chapter2
Summary
nbconvert is a lightweight tool for converting individual notebooks to various formats, while jupyter-book is a comprehensive solution for creating structured, book-like documents from multiple notebooks. nbconvert is simpler to use for basic conversions, but jupyter-book offers more advanced features and customization options for creating polished, multi-page outputs. The choice between the two depends on the complexity of the project and the desired output format.
Voilà turns Jupyter notebooks into standalone web applications
Pros of Voila
- Provides interactive web applications from Jupyter notebooks
- Offers real-time updates and user interactions
- Simplifies deployment of notebook-based dashboards
Cons of Voila
- Limited to web-based output formats
- Requires additional setup for custom widgets and extensions
- May have performance limitations for large-scale applications
Code Comparison
Voila:
# In a Jupyter notebook
import ipywidgets as widgets
slider = widgets.IntSlider(description='Value')
output = widgets.Output()
display(slider, output)
# Voila automatically renders this as an interactive dashboard
NBConvert:
# Command-line usage
jupyter nbconvert --to html notebook.ipynb
# Python API usage
import nbconvert
exporter = nbconvert.HTMLExporter()
html, resources = exporter.from_filename('notebook.ipynb')
Summary
Voila focuses on creating interactive web applications from Jupyter notebooks, offering real-time updates and user interactions. It simplifies the process of deploying notebook-based dashboards but is limited to web-based output formats.
NBConvert, on the other hand, provides a more versatile conversion tool for Jupyter notebooks, supporting various output formats beyond web applications. It offers both command-line and programmatic usage but lacks the interactive features of Voila.
Choose Voila for interactive web dashboards and NBConvert for static conversions to multiple formats.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
nbconvert
Jupyter Notebook Conversion
The nbconvert tool, jupyter nbconvert
, converts notebooks to various other
formats via Jinja templates. The nbconvert tool allows you to convert an
.ipynb
notebook file into various static formats including:
- HTML
- LaTeX
- Reveal JS
- Markdown (md)
- ReStructured Text (rst)
- executable script
Usage
From the command line, use nbconvert to convert a Jupyter notebook (input) to a a different format (output). The basic command structure is:
$ jupyter nbconvert --to <output format> <input notebook>
where <output format>
is the desired output format and <input notebook>
is the
filename of the Jupyter notebook.
Example: Convert a notebook to HTML
Convert Jupyter notebook file, mynotebook.ipynb
, to HTML using:
$ jupyter nbconvert --to html mynotebook.ipynb
This command creates an HTML output file named mynotebook.html
.
Dev Install
Check if pandoc is installed (pandoc --version
); if needed, install:
sudo apt-get install pandoc
Or
brew install pandoc
Install nbconvert for development using:
git clone https://github.com/jupyter/nbconvert.git
cd nbconvert
pip install -e .
Running the tests after a dev install above:
pip install nbconvert[test]
py.test --pyargs nbconvert
Documentation
Technical Support
- Issues and Bug Reports: A place to report bugs or regressions found for nbconvert
- Community Technical Support and Discussion - Discourse: A place for installation, configuration, and troubleshooting assistannce by the Jupyter community. As a non-profit project and maintainers who are primarily volunteers, we encourage you to ask questions and share your knowledge on Discourse.
Jupyter Resources
About the Jupyter Development Team
The Jupyter Development Team is the set of all contributors to the Jupyter project. This includes all of the Jupyter subprojects.
The core team that coordinates development on GitHub can be found here: https://github.com/jupyter/.
Our Copyright Policy
Jupyter uses a shared copyright model. Each contributor maintains copyright over their contributions to Jupyter. But, it is important to note that these contributions are typically only changes to the repositories. Thus, the Jupyter source code, in its entirety is not the copyright of any single person or institution. Instead, it is the collective copyright of the entire Jupyter Development Team. If individual contributors want to maintain a record of what changes/contributions they have specific copyright on, they should indicate their copyright in the commit message of the change, when they commit the change to one of the Jupyter repositories.
With this in mind, the following banner should be used in any source code file to indicate the copyright and license terms:
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
Top Related Projects
Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
📚 Parameterize, execute, and analyze notebooks
Create delightful software with Jupyter Notebooks
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
Create beautiful, publication-quality books and documents from computational content.
Voilà turns Jupyter notebooks into standalone web applications
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot